Hi Alex,
I am sure I have it set correctly, cause I have gone through the
calculation
many time. Anyway, I attached a snippet of my code for your review:
BTW, what does the return value 87 means.
public class RASDIALPARAMS
{
private int charSize = Marshal.SystemDefaultCharSize;
//private const int uintSize = Marshal.SizeOf();
// constants for structure definitions
// 2 bytes for char
private const int SizeOffset = 0;
private const int EntryNameOffset = 4;
private const int PhoneNumberOffset = 46;
private const int CallbackNumberOffset = 304; private const int
UserNameOffset = 402; private const int PasswordOffset = 916; private
const int DomainOffset = 1430; private const int Size = 1464;
private const int RAS_MaxEntryName = (20+1) * 2;
private const int RAS_MaxPhoneNumber = (128+1) * 2;
private const int RAS_MaxCallbackNumber = (48+1) * 2;
private const int ULEN = (256+1) * 2; // 514
private const int PWLEN = (256+1) * 2; // 514
private const int DNLEN = (15+1) *2; // 32
// data member
public uint dwSize;
public string szEntryName;
public string szPhoneNumber;
public string szCallbackNumber;
public string szUserName;
public string szPassword;
public string szDomain;
Maybe you can spot my mistake.
Thanks
:
My guess is that you've made a mistake in the field offsets of the
RasDialParams
--
Alex Feinman
---
Visit
http://www.opennetcf.org
I set the size to 1464. That doesn't help. I still get the return
value
of
87.
BTW, what is the meaning of the 87.
Could it be cause by other parameter like?
:
Could you try the size of RasDialParam set to 1464?
--
Alex Feinman
---
Visit
http://www.opennetcf.org
Hi,
I have alter my code, but now i got the rasdial function
returning
error
value of 87.
What went wrong?
Below is the my code: btnDial button will invoke the Rasdial
function,
which
get the entry name from RasEnumEntries. I manage to ge the
RasEnumEntries
to
work using the byte array method. Now I am using the same method
with
Rasdial.
private void btnDial_Click(object sender, System.EventArgs e)
{
int dwError;
IntPtr handle;
myMessageWindow messageWindow;
messageWindow = new myMessageWindow();
try
{
RASDIALPARAMS rdp= new RASDIALPARAMS();
byte[] rdpBytes = rdp.ToByteArray();
rdp.szEntryName = strEntry; // retrieve from one of the
return
string from RasEnumEntries;
rdp.szPhoneNumber="62819749";
rdp.szCallbackNumber="123";
rdp.szDomain="";
rdp.szUserName="";
rdp.szPassword="";
rdp.SetByteArray(rdpBytes); // based on the byte array method
of
setting
the array
//making a dial
dwError = rayRAS.RasDial(IntPtr.Zero
,null,rdpBytes,0xffffff,messageWindow.Hwnd ,out handle1);
MessageBox.Show(dwError.ToString(),"");
}
catch(Exception ex)
{
throw new Exception("RASDIAL: "+ ex.Message);
}
}
:
There are several things wrong with this code
RasDial is defined as
DWORD RASAPI RasDial (LPRASDIALEXTENSIONS dialExtensions,
LPTSTR phoneBookPath,
LPRASDIALPARAMS rasDialParam,
DWORD NotifierType,
LPVOID notifier,
LPHRASCONN pRasConn);
The P/Invoke definition for it should be
static extern int RasDial (IntPtr dialExtensions,
string phoneBookPath,
byte[] rasDialParam,
int NotifierType,
IntPtr notifier,
[out] IntPtr hRasConn)
You certainly cannot pass Form as the Notifier parameter. A
MessageWindow
hWnd would do.
The byte array allocated for RasDialParam must be properly sized
and
the
cbSize member (the first DWORD must be set to match the
allocation
size.
The structure size must be 4 + (RAS_MaxEntryName + 1) * 2 + (
RAS_MaxPhoneNumber + 1) * 2 +
(RAS_MaxCallbackNumber + 1) * 2 + (UNLEN + 1) * 2 + (PWLEN + 1)
* 2
+
(DNLEN
+ 1) * 2 =
4 + 21 * 2 + 129 * 2 + 49 * 2 + 257 * 2 + 257 * 2 + 16 * 2 =
1462
Set rasDialParam[0] to 0xb6 and rasDialParam[1] to 5
--
Alex Feinman
---
Visit
http://www.opennetcf.org
Hi,
I am having prolem with calling RasDial from compact framwork
when I
rewrite
the RASDIALSPARAM structure to marshal in as byte array.
My function call the RasDial with the following format:
dwError =
rayRAS.RasDial(null,null,null,0xFFFFFFFF,dlg,handle);
where dlg is a defined as
public frmDlg dlg = new frmDlg();
and handle is a type of IntPtr
I only set the EntryName parameter in the byte array for
RASDIALSPARAM,
the
reset is assigned as "".
I am getting the error: 0xC0000005.
Can anyone enlightened me?
Thanks