首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >RasGetEntryProperties返回所有零

RasGetEntryProperties返回所有零
EN

Stack Overflow用户
提问于 2015-07-14 08:56:24
回答 1查看 320关注 0票数 0

我试图使用RasGetEntryProperties获取有关我的一个电话簿条目的信息,但当我这样做时,返回的RASENTRY结构包含除dwSizedwOptions以外的所有元素的零或空白。

我不完全了解这些数据是如何工作的,但我想我至少应该看到存储在电话簿中的设备名称或电话号码……

这是我的代码:

代码语言:javascript
复制
        uint dwEntryInfoSize = 0;
        uint i = RasGetEntryProperties(null, "", IntPtr.Zero, ref dwEntryInfoSize, IntPtr.Zero, IntPtr.Zero);


        RASENTRY getRasEntry = new RASENTRY();
        string entryName = "Dial-up Connection test";
        getRasEntry.dwSize = (int)dwEntryInfoSize;

        IntPtr ptrRasEntry = Marshal.AllocHGlobal((int)dwEntryInfoSize);
        Marshal.StructureToPtr(getRasEntry, ptrRasEntry, false);

        uint j = RasGetEntryProperties(null, entryName, ptrRasEntry, ref dwEntryInfoSize, IntPtr.Zero, IntPtr.Zero);

        RASENTRY outRasEntry = (RASENTRY)Marshal.PtrToStructure(ptrRasEntry, typeof(RASENTRY));
        Marshal.FreeHGlobal(ptrRasEntry);

下面是Visual调试器中outRasEntry的部分屏幕截图.

编辑这里是我对RASENTRY的定义

代码语言:javascript
复制
    const int MAX_PATH = 260;

    [StructLayout(LayoutKind.Sequential)]
    public struct RASENTRY
    {
          public int       dwSize;
          public int       dwfOptions;
          public int       dwCountryID;
          public int       dwCountryCode;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) RasFieldSizeConstants.RAS_MaxAreaCode+1)]
          public string       szAreaCode;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) RasFieldSizeConstants.RAS_MaxPhoneNumber+1)]
          public string       szLocalPhoneNumber;
          public int       dwAlternateOffset;
          public RASIPADDR   ipaddr;
          public RASIPADDR   ipaddrDns;
          public RASIPADDR   ipaddrDnsAlt;
          public RASIPADDR   ipaddrWins;
          public RASIPADDR   ipaddrWinsAlt;
          public int       dwFrameSize;
          public int       dwfNetProtocols;
          public int       dwFramingProtocol;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) MAX_PATH)]
          public string       szScript;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) MAX_PATH)]
          public string       szAutodialDll;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) MAX_PATH)]
          public string       szAutodialFunc;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) RasFieldSizeConstants.RAS_MaxDeviceType + 1)]
          public string       szDeviceType;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) RasFieldSizeConstants.RAS_MaxDeviceName + 1)]
          public string       szDeviceName;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) RasFieldSizeConstants.RAS_MaxPadType + 1)]
          public string       szX25PadType;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) RasFieldSizeConstants.RAS_MaxX25Address + 1)]
          public string       szX25Address;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) RasFieldSizeConstants.RAS_MaxFacilities + 1)]
          public string       szX25Facilities;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) RasFieldSizeConstants.RAS_MaxUserData + 1)]
          public string       szX25UserData;
          public int       dwChannels;
          public int       dwReserved1;
          public int       dwReserved2;
          public int       dwSubEntries;
          public int       dwDialMode;
          public int       dwDialExtraPercent;
          public int       dwDialExtraSampleSeconds;
          public int       dwHangUpExtraPercent;
          public int       dwHangUpExtraSampleSeconds;
          public int       dwIdleDisconnectSeconds;
          public int       dwType;
          public int       dwEncryptionType;
          public int       dwCustomAuthKey;
          public Guid        guidId;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) MAX_PATH)]
          public string       szCustomDialDll;
          public int       dwVpnStrategy;
          public int       dwfOptions2;
          public int       dwfOptions3;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) RasFieldSizeConstants.RAS_MaxDnsSuffix)]
          public string       szDnsSuffix;
          public int       dwTcpWindowSize;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) MAX_PATH)]
          public string       szPrerequisitePbk;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
                (int) RasFieldSizeConstants.RAS_MaxEntryName)]
          public string       szPrerequisiteEntry;
          public int       dwRedialCount;
          public int       dwRedialPause;
          RASIPV6ADDR ipv6addrDns;
          RASIPV6ADDR ipv6addrDnsAlt;
          public int       dwIPv4InterfaceMetric;
          public int       dwIPv6InterfaceMetric;
          RASIPV6ADDR ipv6addr;
          public int       dwIPv6PrefixLength;
          public int       dwNetworkOutageTime;
    }

public enum RasFieldSizeConstants
{
    RAS_MaxDeviceType = 16,
    RAS_MaxPhoneNumber = 128,
    RAS_MaxIpAddress = 15,
    RAS_MaxIpxAddress = 21,
    RAS_MaxEntryName = 256,
    RAS_MaxDeviceName = 128,
    RAS_MaxCallbackNumber = RAS_MaxPhoneNumber,
    RAS_MaxAreaCode = 10,
    RAS_MaxPadType = 32,
    RAS_MaxX25Address = 200,
    RAS_MaxFacilities = 200,
    RAS_MaxUserData = 200,
    RAS_MaxReplyMessage = 1024,
    RAS_MaxDnsSuffix = 256,
    UNLEN = 256,
    PWLEN = 256,
    DNLEN = 15
}

    public struct RASIPADDR {
        byte a;
        byte b;
        byte c;
        byte d;
    }

    public struct RASIPV6ADDR
    {
        byte a;
        byte b;
        byte c;
        byte d;
        byte e;
        byte f;
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-14 10:20:58

谢谢leppie为我指明了dotras.codeplex.com的方向-尽管我最终没有使用那个库,但是查看它的源代码帮助我修复了我自己的.

关键在于RASENTRY的定义.下面第一行的改动使它发挥了作用。

代码语言:javascript
复制
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 4)]
public struct RASENTRY
{
    public int       dwSize;
    public int       dwfOptions;
    public int       dwCountryID;
    public int       dwCountryCode;

// etc.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31402123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档