Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ras structures in C#

11 views
Skip to first unread message

Juve

unread,
Oct 14, 2001, 6:30:42 PM10/14/01
to
I'm trying to use the Rasdial function in C# and am having trouble getting
it to work.

I think the problem is properly expressing the structures that the Rasdial
function takes. The structures are :
typedef struct tagRASDIALEXTENSIONS {
DWORD dwSize;
DWORD dwfOptions;
HWND hwndParent;
ULONG_PTR reserved;
#if (WINVER >= 0x500)
ULONG_PTR reserved1;
RASEAPINFO RasEapInfo;
#endif
} RASDIALEXTENSIONS;
Since this structure can be null, I express it as an int type in the fuction
declaration and pass in 0 (by value or null).

and

typedef struct _RASDIALPARAMS {
DWORD dwSize;
TCHAR szEntryName[RAS_MaxEntryName + 1];
TCHAR szPhoneNumber[RAS_MaxPhoneNumber + 1];
TCHAR szCallbackNumber[RAS_MaxCallbackNumber + 1];
TCHAR szUserName[UNLEN + 1];
TCHAR szPassword[PWLEN + 1];
TCHAR szDomain[DNLEN + 1] ;
#if (WINVER >= 0x401)
DWORD dwSubEntry;
ULONG_PTR dwCallbackId;
#endif
} RASDIALPARAMS;
I've been expressing the various TCHAR parameters as string type in C# but
that doesn't seem to work.

RasDial is defined as :
DWORD RasDial(
LPRASDIALEXTENSIONS lpRasDialExtensions,
// pointer to function extensions data
LPCTSTR lpszPhonebook, // pointer to full path and file
// name of phone-book file
LPRASDIALPARAMS lpRasDialParams,
// pointer to calling parameters data
DWORD dwNotifierType, // specifies type of RasDial event handler
LPVOID lpvNotifier, // specifies a handler for RasDial events
LPHRASCONN lphRasConn // pointer to variable to receive
// connection handle
);

I've tried using the following:
public static extern int RasDial(int lpRasDialExtentions, string
lpszPhonebook, ref RASDIALPARAMS lpRasDialParams, int dwNotifierType, int
lpvNotifier, ref int lphRasConn);
I always get an incorrect structure size error
Any ideas?


Thanks


NETMaster

unread,
Oct 15, 2001, 7:43:52 AM10/15/01
to
also read PInvoke sample at
http://www.gotdotnet.com/userarea/keywordsrch.aspx?keyword=sonjake


// ======================================================================
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack=4, CharSet=CharSet.Auto)]
struct RASDIALPARAMS
{
public int dwSize;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=257)]
public string szEntryName;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=129)]
public string szPhoneNumber;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=129)]
public string szCallbackNumber;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=257)]
public string szUserName;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=257)]
public string szPassword;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=16)]
public string szDomain;
}


[DllImport("rasapi32.dll", CharSet=CharSet.Auto) ]
public static extern int RasDial( IntPtr dummy, string lpszPhonebook,


ref RASDIALPARAMS lpRasDialParams, int dwNotifierType,

IntPtr lpvNotifier, ref IntPtr lphRasConn );

RASDIALPARAMS par;
par.dwSize = Marshal.SizeOf(typeof(RASDIALPARAMS));
par.szEntryName = "";
par.szPhoneNumber = "123";
par.szCallbackNumber = "";
par.szUserName = "";
par.szPassword = "";
par.szDomain = "";
IntPtr rashand = IntPtr.Zero;
IntPtr hwnd = IntPtr.Zero;
int rc = RasDial( IntPtr.Zero, null,
ref par, -1, hwnd, ref rashand );

// ======================================================================

NETMaster
http://www.cetus-links.org/oo_csharp.html

"Juve" <juv...@hotmail.com> wrote in message
news:Obp8E9PVBHA.2144@tkmsftngp05...

0 new messages