import dll c++ function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Any body knows how to convert this DLL function to C# ?

DWORD WINAPI
importfunction(LPSTR lpBuffer, LPDWORD nSize);
 
centrino said:
Any body knows how to convert this DLL function to C# ?

DWORD WINAPI
importfunction(LPSTR lpBuffer, LPDWORD nSize);

[System.Runtime.InteropServices.DllImport(my.dll)]
static extern System.Int32
importfunction([System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)]
string lpBuffer,
System.IntPtr nSize
);


If this is from a Win32 function you can probably find it at

http://pinvoke.net/

-- Alan
 
centrino said:
Any body knows how to convert this DLL function to C# ?

DWORD WINAPI
importfunction(LPSTR lpBuffer, LPDWORD nSize);


[DllImport("your.dll", CallingConvention = CallingConvention.StdCall)]
static extern importfunction
(
[MarshalAs(UnmanagedType.LPTStr)]
string lpBuffer,
ref int nSize
);

Willy.
 
I don't know why i still get a empty buffer :

there is a other similar function:

DWORD WINAPI importfunction(
LPWSTR lpBuffer,
LPDWORD nSize
);


[DllImport("mydll", SetLastError=true)]
private static extern uint importfunction(

[MarshalAs(UnmanagedType.LPWStr)]
StringBuilder pBuffer,
ref uint pBufferSize
);

Willy Denoyette said:
centrino said:
Any body knows how to convert this DLL function to C# ?

DWORD WINAPI
importfunction(LPSTR lpBuffer, LPDWORD nSize);


[DllImport("your.dll", CallingConvention = CallingConvention.StdCall)]
static extern importfunction
(
[MarshalAs(UnmanagedType.LPTStr)]
string lpBuffer,
ref int nSize
);

Willy.
 
centrino said:
I don't know why i still get a empty buffer :

there is a other similar function:

DWORD WINAPI importfunction(
LPWSTR lpBuffer,
LPDWORD nSize
);


[DllImport("mydll", SetLastError=true)]
private static extern uint importfunction(

[MarshalAs(UnmanagedType.LPWStr)]
StringBuilder pBuffer,
ref uint pBufferSize
);

:

Sorry but this is not the signature I've posted, WINAPI means stdcall
calling convention, why did you change it.
Also changed is the string argument, now it is a LPWSTR, why the change?

Did you allocate a StringBuilder big enough to hold the returned string?
What is there returned as nSize?
The problem with PInvoke is that you really need the description of the
function, else you have to guess things like:
- LPWSTR is what a fixed size buffer or not, who allocates the buffer?
- nSize is what the size of the buffer returned or the size requested?

Willy.
 
Hi Willy,

Thanks for your post !

I get the the size of the buffer returned nSize, but i "see" notthing in
StringBuffer lpBuffer.
StringBuilder lpBuffer = new StringBuilder(256);

The function return ERROR_SUCCESS=0 and NDIS_ERROR_SUCCESS=0. It seems
correct !?

i dont know why ! I tryed to get buffer with byte[], but i get notthing.

regards




Willy Denoyette said:
centrino said:
I don't know why i still get a empty buffer :

there is a other similar function:

DWORD WINAPI importfunction(
LPWSTR lpBuffer,
LPDWORD nSize
);


[DllImport("mydll", SetLastError=true)]
private static extern uint importfunction(

[MarshalAs(UnmanagedType.LPWStr)]
StringBuilder pBuffer,
ref uint pBufferSize
);

:

Sorry but this is not the signature I've posted, WINAPI means stdcall
calling convention, why did you change it.
Also changed is the string argument, now it is a LPWSTR, why the change?

Did you allocate a StringBuilder big enough to hold the returned string?
What is there returned as nSize?
The problem with PInvoke is that you really need the description of the
function, else you have to guess things like:
- LPWSTR is what a fixed size buffer or not, who allocates the buffer?
- nSize is what the size of the buffer returned or the size requested?

Willy.
 
Hello Willy,

I get it:

byte[] dsc=new byte[256];

blength=(uint) dsc.Length;

ioResult = importfunction(
dsc,
ref blength
);

and:

string aname=Encoding.ASCII.GetString(dsc).Trim((char)0x00);

centrino said:
Hi Willy,

Thanks for your post !

I get the the size of the buffer returned nSize, but i "see" notthing in
StringBuffer lpBuffer.
StringBuilder lpBuffer = new StringBuilder(256);

The function return ERROR_SUCCESS=0 and NDIS_ERROR_SUCCESS=0. It seems
correct !?

i dont know why ! I tryed to get buffer with byte[], but i get notthing.

regards




Willy Denoyette said:
centrino said:
I don't know why i still get a empty buffer :

there is a other similar function:

DWORD WINAPI importfunction(
LPWSTR lpBuffer,
LPDWORD nSize
);


[DllImport("mydll", SetLastError=true)]
private static extern uint importfunction(

[MarshalAs(UnmanagedType.LPWStr)]
StringBuilder pBuffer,
ref uint pBufferSize
);

:

Sorry but this is not the signature I've posted, WINAPI means stdcall
calling convention, why did you change it.
Also changed is the string argument, now it is a LPWSTR, why the change?

Did you allocate a StringBuilder big enough to hold the returned string?
What is there returned as nSize?
The problem with PInvoke is that you really need the description of the
function, else you have to guess things like:
- LPWSTR is what a fixed size buffer or not, who allocates the buffer?
- nSize is what the size of the buffer returned or the size requested?

Willy.
 
centrino said:
Hi Willy,

Thanks for your post !

I get the the size of the buffer returned nSize, but i "see" notthing in
StringBuffer lpBuffer.
StringBuilder lpBuffer = new StringBuilder(256);

The function return ERROR_SUCCESS=0 and NDIS_ERROR_SUCCESS=0. It seems
correct !?

i dont know why ! I tryed to get buffer with byte[], but i get notthing.

regards

What's the Length of the SB reurned?
Did yoy try lpBuffer.ToString()?
Are you sure the buffer contains a UNICODE string?
What function are you calling exactly?

Willy.
 
Back
Top