关于用C#进行P/Invoke调用的问题,求高人帮助~
各位专家,最近我尝试通过调用API函数CreateIpForwardEntry2来修改VISTA下的路由表,GetLastWin32Error返回的结果表明调用成功,但是API函数的返回值是87(参数传递错误),这几天一直在折腾这个问题,自己实在是难以解决了,只好到这里寻求专家的帮助了。哪位高人能够帮助小弟用C#实现这个调用?不胜感激!下面是SDK里函数和参数的部分描述,我给摘到这里来了。
CreateIpForwardEntry2
The CreateIpForwardEntry2 function creates a new IP route entry on the local computer.
NETIOAPI_API CreateIpForwardEntry2(
const MIB_IPFORWARD_ROW2* Row
);
MIB_IPFORWARD_ROW2
The MIB_IPFORWARD_ROW2 structure stores information about an IP route entry.
typedef struct _MIB_IPFORWARD_ROW2 {
NET_LUID Inte易做图ceLuid;
NET_IFINDEX Inte易做图ceIndex;
IP_ADDRESS_PREFIX DestinationPrefix;
SOCKADDR_INET NextHop;
UCHAR SitePrefixLength;
ULONG ValidLifetime;
ULONG PreferredLifetime;
ULONG Metric;
NL_ROUTE_PROTOCOL Protocol;
BOOLEAN Loopback;
BOOLEAN AutoconfigureAddress;
BOOLEAN Publish;
BOOLEAN Immortal;
ULONG Age;
NL_ROUTE_ORIGIN Origin;
} MIB_IPFORWARD_ROW2,
*PMIB_IPFORWARD_ROW2;
NET_LUID
The NET_LUID structure is the locally unique identfier (LUID) for a network inte易做图ce.
typedef union _NET_LUID {
ULONG64 Value;
struct {
ULONG64 Reserved :24;
ULONG64 NetLuidIndex :24;
ULONG64 IfType :16;
} Info;
} NET_LUID,
*PNET_LUID;
IP_ADDRESS_PREFIX
The IP_ADDRESS_PREFIX structure stores an IP address prefix.
typedef struct _IP_ADDRESS_PREFIX {
SOCKADDR_INET Prefix;
UINT8 PrefixLength;
} IP_ADDRESS_PREFIX,
*PIP_ADDRESS_PREFIX;
SOCKADDR_INET
The SOCKADDR_INET union contains an IPv4 or IPv6 address and address family.
typedef union _SOCKADDR_INET {
SOCKADDR_IN Ipv4;
SOCKADDR_IN6 Ipv6;
ADDRESS_FAMILY si_family;
} SOCKADDR_INET,
*PSOCKADDR_INET;
struct sockaddr_in {
short sin_family;
u_short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
};
struct sockaddr_in6 {
short sin6_family;
u_short sin6_port;
u_long sin6_flowinfo;
struct in6_addr sin6_addr;
u_long sin6_scope_id;
}; --------------------编程问答-------------------- 使用C++写好一个DLL然后调用下,
可能要比直接平台调用方便点吧
补充:.NET技术 , C#