[Q]How to call RasGetErrorString in the RASAPI

S

Stuart Norris

Hello Group,

I am trying retreive a string with error information from the RASAPI
using C#.

Currently I am always getting blank string returned from the call to
RasGetErrorString, even though the command returns success indicating
success.

From the msdn doco the RasGetErrorString API (via rasapi32.dll) is

DWORD RasGetErrorString(
UINT uErrorValue,
LPTSTR lpszErrorString,
DWORD cBufSize
);

uErrorValue
[in] Specifies the error value of interest. These are values returned
by one of the RAS functions: those listed in the RasError.h header
file.
lpszErrorString
[out] Pointer to a buffer that receives the error string. This
parameter must not be NULL.
cBufSize
[in] Specifies the size, in characters, of the buffer pointed to by
lpszErrorString.


Please find attached an example program the tries to retreive the
string for error code 652 - "Unrecognised response from the device".

This example program always returns a blank string for any error
message.

Could it be explained what I have implemented incorrectly here?

Thanks

Stuart

using System;
using System.Runtime.InteropServices;
namespace RasGetErrorString
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Class1 class1 = new Class1();
string errorMessage = class1.RasErrorMesssge(652);
}

public string RasErrorMesssge(uint rasError)
{
string RASErrorMessage = new string (' ', 255);
if (WINDOWSRASAPI.RasGetErrorString((uint)rasError,
RASErrorMessage, (int) 255) == (uint) 0)
return RASErrorMessage;
else
return string.Empty;
}

}

public sealed class WINDOWSRASAPI
{
[DllImport("rasapi32.dll", SetLastError=true)]
internal extern static uint RasGetErrorString(
[In] uint uErrorValue,
[Out] string lpszErrorString,
[In] int cBufSize
);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top