帮助转换结构 [英] Help with converting structure
问题描述
我目前正在创建一个与winapi RAS函数和枚举类型接口的类。我需要将此函数转换为C#调用。
I am currently creating a class to interface with the winapi RAS functions and enumerate types. I need to translate this function into a C# call.
void CALLBACK MprAdminConnectionHangupNotification( __in RAS_CONNECTION_0 *pRasConnection0, __in RAS_CONNECTION_1 *pRasConnection1 );
最初,我认为这很简单 内部
Initially, i thought this was easy internal
[StructLayout(LayoutKind.Sequential,CharSet = CharSet.Auto)]
internal struct RAS_CONNECTION_0
{
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
internal struct RAS_CONNECTION_0
{
内部 readonly int MAX_INTERFACE_NAME_LEN = 256;
IntPtr hConnection;
IntPtr hInterface;
public uint dwConnectDuration;
RouterInterfaceType dwInterfaceType;
public uint dwConnectionFlags; < br> [MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )256)] public string wszInterfaceName; [MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )256)] public string wszUserName;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )256)] public string wszLogonDomain;
[MarshalAs(UnmanagedType) .ByValTStr,SizeConst =( int )256)] public string wszRemoteComputer;
internal readonly int MAX_INTERFACE_NAME_LEN =256;
IntPtr hConnection;
IntPtr hInterface;
public uint dwConnectDuration;
RouterInterfaceType dwInterfaceType;
public uint dwConnectionFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int) 256)] public string wszInterfaceName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int) 256)] public string wszUserName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int) 256)] public string wszLogonDomain;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int) 256)] public string wszRemoteComputer;
};
< br>原始结构是
};
The Original structure is
typedef struct _RAS_CONNECTION_0 {
HANDLE hConnection;
HANDLE hInterface;
DWORD dwConnectDuration;
ROUTER_INTERFACE_TYPE dwInterfaceType;
DWORD dwConnectionFlags;
WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1];
WCHAR wszUserName[UNLEN + 1];
WCHAR wszLogonDomain[DNLEN + 1];
WCHAR wszRemoteComputer[NETBIOS_NAME_LEN + 1]; } RAS_CONNECTION_0,
*PRAS_CONNECTION_0;
Can Someone tell me where to find UNLEN and DNLEN?
I am close to solving the hang up problem, I just need some assistance as to where to locate mpradmin.h.
Thanks in advanced
< hr size ="1"align ="left"width ="25%"> David Moss
David Moss
推荐答案
我的代码返回用户名,域等。我的问题在于hConnection。它返回一个负值,当从隔离区调用Remove时,错误1168出现。
我希望这可以帮到你。你的代码中有unlen和dnlen。
[
My code is returning user name,domain and so on. My problem is in hConnection. It's returning a negative value, when calling Remove from quarantine the error 1168 comes up.
I hope this helps you. You have unlen and dnlen in the code.
[
StructLayout ( LayoutKind 。顺序,CharSet = CharSet .Auto)] StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
内部 struct RAS_CONNECTION_0 internal struct RAS_CONNECTION_0 { public IntPtr hConnection; public IntPtr hConnection;
public IntPtr hInterface; public IntPtr hInterface;
public uint dwConnectDuration; public uint dwConnectDuration;
public < span style ="color:#2b91af; font-size:x-small"> ROUTER_INTERFACE_TYPE public ROUTER_INTERFACE_TYPE dwInterfaceType;
public < span style ="font-size:x-small"> [ public uint dwConnectionFlags;
[ MarshalAs ( UnmanagedType 。ByValTStr,SizeConst =( int )257)] MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)257)]
public string wszInterfaceName; [ public string wszInterfaceName;
[ MarshalAs ( UnmanagedType .ByValTStr,SizeConst =( int )257)] MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)257)]
public string wszUserName; [ public string wszUserName;
[ MarshalAs ( UnmanagedType 。ByValTStr,SizeConst =( int )16)] MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)16)]
public string wszLogonDomain; [ public string wszLogonDomain;
[ MarshalAs ( UnmanagedType 。ByValTStr,SizeConst = ( int )17)] MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)17)]
public string wszRemoteComputer; }; public string wszRemoteComputer;
}; #region 代码 code
public enum ROUTER_INTERFACE_TYPE public enum ROUTER_INTERFACE_TYPE { ROUTER_IF_TYPE_CLIENT, ROUTER_IF_TYPE_CLIENT, ROUTER_IF_TYPE_HOME_ROUTER, ROUTER_IF_TYPE_HOME_ROUTER, ROUTE R_IF_TYPE_FULL_ROUTER, ROUTER_IF_TYPE_FULL_ROUTER, ROUTER_IF_TYPE_DEDICATED, ROUTER_IF_TYPE_DEDICATED, ROUTER_IF_TYPE_INTERNAL, ROUTER_IF_TYPE_INTERNAL, ROUTER_IF_TYPE_LOOPBACK, ROUTER_IF_TYPE_LOOPBACK, ROUTER_IF_TYPE_DIALOUT ROUTER_IF_TYPE_DIALOUT } #endregion #endregion 代码 这篇关于帮助转换结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!