VB.net RASENTRY实现问题,Windows Vista [英] VB.net RASENTRY implementation Issue, Windows Vista
问题描述
过去几天我一直在努力从VB.net中的Rasapi32.dll实现RASENTRY结构。我完全按照Ras.h文件中的结构和MSDN站点上的结构,但在调用RasGetEntryProperties时总是得到ERROR_INVALID_SIZE。我的目标是通过调用RasSetEntryProperties来添加新的条目连接,但是一直使用RasGetEntryProperties来测试当前条目。如果任何人对我可能做错的事情有任何建议或见解,那将会非常令人沮丧。我包含了我正在使用的所有相关代码。提前感谢您的帮助。
我不知道你是如何进行字符串编组的在VB中,但我想你可能会错过szCustomDialDll的声明。
在C#中看起来像: / p>
[
MarshalAs ( < font color ="#2b91af"size = 2> UnmanagedType .ByValTStr,SizeConst = MAX_PATH)]
public string szCustomDialDll;
我有相同的"尺寸"尝试在最新版本的RASENTRY结构中包含所有字段时尝试使用Windows Mobile 5创建连接的问题。如果我将结构限制在下面的代码中,我可以让它工作。但它并没有完全建立连接。看起来我还需要在RasSetEntryProperties中普及 lpbDeviceInfo 以创建可用的连接。
干杯,
格雷厄姆
public class 条目 {
< blockquote>
public int dwSize;
public uint dwfOptions;
//
//位置/电话号码。
//
public int dwCountryID;
public < font size = 2> int dwCountryCode;
[
MarshalAs ( UnmanagedType .ByValTStr,SizeConst = RAS_MaxAreaCode + 1)]
public string szAreaCode;
[
MarshalAs ( UnmanagedType .ByValTStr,SizeConst = RAS_MaxPhoneNumber + 1)]
public string szLocalPhoneNumber;
public int dwAlternateOffset;
//
// PPP / Ip
//
< font color ="#0000ff"size = 2> 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 = MAX_PATH)]
public string szScript;
//
// AutoDial
//
[
MarshalAs ( UnmanagedType .ByValTStr,SizeConst = MAX_PATH)]
public string szAutodialDll;
[
MarshalAs ( UnmanagedType .ByValTStr,SizeConst = MAX_PATH)]
public string szAutodialFunc;
//
//设备
< font color ="#008000"size = 2> //
[
MarshalAs ( UnmanagedType .ByValTStr,SizeConst = RAS_MaxDeviceType + 1)]
public string szDeviceType;
[
MarshalAs ( UnmanagedType .ByValTStr,SizeConst = RAS_MaxDeviceName + 1)]
public string szDeviceName;
/ /
// X.25
//
[
MarshalAs ( UnmanagedType .ByValTStr,SizeConst = RAS_MaxPadType + 1)]
public string szX25PadType;
[
MarshalAs ( UnmanagedType .ByValTStr,SizeConst = RAS_MaxX25Address + 1)]
public
string szX25Address;
[
MarshalAs ( UnmanagedType .ByValTStr,SizeConst = RAS_MaxFacilities + 1)]
public string szX25Facilities;
[
MarshalAs ( UnmanagedType .ByValTStr,SizeConst = RAS_MaxUserData + 1)]
public string szX25UserData;
public int dwChannels;
//
//保留
//
public int dwReserved1;
public int dwReserved2;
public int dwCustomAuthKey;
}
I have been struggling for the last few days to implement the RASENTRY structure from the Rasapi32.dll in VB.net. I have followed the structure from the Ras.h file exactly and from what is on the MSDN site, but always get ERROR_INVALID_SIZE when calling RasGetEntryProperties. My goal is to be able to add a new entry connection by calling RasSetEntryProperties, but have been using RasGetEntryProperties for testing with a current entry. If anyone has any suggestions or insights on what I may be doing wrong it would be greatly apreciated. I am including all relevant code that I am using. Thanks ahead of time for the help.
Hi, I'm not sure how you do your marshalling of strings in VB, but I think you might be missing the declaration for szCustomDialDll.
In C# that looks like:
[
MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] public string szCustomDialDll;
I'm have the same "size" problem trying to create connections using Windows Mobile 5 when I try to include all the fields in the most recent version of the RASENTRY structure. I can get it to work though if I limit my struct to the code below. It doesn't completely create a connection though. Looks like I also need to populat lpbDeviceInfo in RasSetEntryProperties to create a usable connection.
Cheers,
Graham
public class Entry {public int dwSize; public uint dwfOptions; // // Location/phone number. // public int dwCountryID; public int dwCountryCode;[
MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxAreaCode + 1)] public string szAreaCode;[
MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxPhoneNumber + 1)] public string szLocalPhoneNumber; public int dwAlternateOffset; // // PPP/Ip // public RasIpAddr ipaddr; public RasIpAddr ipaddrDns; public RasIpAddr ipaddrDnsAlt; public RasIpAddr ipaddrWins; public RasIpAddr ipaddrWinsAlt; // // Framing // public int dwFrameSize; public int dwfNetProtocols; public int dwFramingProtocol; // // Scripting //[
MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] public string szScript; // // AutoDial //[
MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] public string szAutodialDll;[
MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] public string szAutodialFunc; // // Device //[
MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceType + 1)] public string szDeviceType;[
MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceName + 1)] public string szDeviceName; // // X.25 //[
MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxPadType + 1)] public string szX25PadType;[
MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxX25Address + 1)] public string szX25Address;[
MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxFacilities + 1)] public string szX25Facilities;[
MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxUserData + 1)] public string szX25UserData; public int dwChannels; // // Reserved // public int dwReserved1; public int dwReserved2; public int dwCustomAuthKey;}
这篇关于VB.net RASENTRY实现问题,Windows Vista的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!