How to P/Invoke the RasGetEntryDialParams method??

  • Thread starter Thread starter Roberto Rocco
  • Start date Start date
R

Roberto Rocco

Hello,

Can anybody provide a code snippet of how to P/Invoke RasGetEntryDialParams?

Anytime we try it the function returns with an errorcode 87 (invalid
parameters).

I guess the problem lies in the LPRASDIALPARAMS struct members which
probably aren't set correctly.

Many thanks in advance.

Roberto Rocco.
 
Hello Alex,

Thank you for your reply. Unfortunately I still don't get it to work, I
still get an error-code 87 after calling RasGetEntryDialParams...
Can you see anything wrong from my code below???

Many thanks in advance,

Roberto.


[DllImport("coredll.dll", CharSet=CharSet.Auto, SetLastError=true)]
private static extern UInt32 RasGetEntryDialParams(
string lpszPhoneBook,
byte[] lpRasDialParams,
ref bool lpfPassword
);

public class RasDialParams : CustomMarshaler
{
private const int RAS_MaxEntryName = 20;
private const int RAS_MaxPhoneNumber = 128;
private const int RAS_MaxCallbackNumber = 48;
private const int UNLEN = 256;
private const int PWLEN = 256;
private const int DNLEN = 15;

public uint dwSize;

[CustomMarshalAs(SizeConst = RAS_MaxEntryName +1)]
public string szEntryName;

[CustomMarshalAs(SizeConst = RAS_MaxPhoneNumber +1)]
public string szPhoneNumber;

[CustomMarshalAs(SizeConst = RAS_MaxCallbackNumber +1)]
public string szCallbackNumber;

[CustomMarshalAs(SizeConst = UNLEN+1)]
public string szUserName;

[CustomMarshalAs(SizeConst = PWLEN+1)]
public string szPassword;

[CustomMarshalAs(SizeConst = DNLEN+1)]
public string szDomain;


public RasDialParams()
{
dwSize = (uint)GetSize();
this.data = new byte[dwSize];
//Write the dwSize into the byte array
this.Serialize();
}
}

private void button1_Click(object sender, System.EventArgs e)
{
RasDialParams DialParams = new RasDialParams();
bool Pass = true;
UInt32 ret = RasGetEntryDialParams ("Arcor", DialParams.ByteArray, ref
Pass); // Always returning with 87!!!
// Populate the fields from returned byte array
DialParams.Deserialize();
}
 
Back
Top