"centrino" <centrino@discu ssions.microsof t.com> wrote in message
news:459EB6EC-2AC5-4848-92E2-D963EAF58353@mi crosoft.com...[color=blue]
> Any body knows how to convert this DLL function to C# ?
>
> DWORD WINAPI
> importfunction( LPSTR lpBuffer, LPDWORD nSize);[/color]
"centrino" <centrino@discu ssions.microsof t.com> wrote in message
news:459EB6EC-2AC5-4848-92E2-D963EAF58353@mi crosoft.com...[color=blue]
> Any body knows how to convert this DLL function to C# ?
>
> DWORD WINAPI
> importfunction( LPSTR lpBuffer, LPDWORD nSize);
>[/color]
[DllImport("your .dll", CallingConventi on = CallingConventi on.StdCall)]
static extern importfunction
(
[MarshalAs(Unman agedType.LPTStr )]
string lpBuffer,
ref int nSize
);
"centrino" <centrino@discu ssions.microsof t.com> wrote in message
news:04E12B6F-66CE-4B87-BFC5-674E7EC80510@mi crosoft.com...[color=blue]
>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("mydl l", SetLastError=tr ue)]
> private static extern uint importfunction(
>
> [MarshalAs(Unman agedType.LPWStr )]
> StringBuilder pBuffer,
> ref uint pBufferSize
> );
>
> "Willy Denoyette [MVP]" wrote:
>[/color]
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?
"centrino" <centrino@discu ssions.microsof t.com> wrote in message
news:B72B2C41-D57B-4D7D-BD42-F2AD0BFA5DBB@mi crosoft.com...[color=blue]
> 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(2 56);
>
> The function return ERROR_SUCCESS=0 and NDIS_ERROR_SUCC ESS=0. It seems
> correct !?
>
> i dont know why ! I tryed to get buffer with byte[], but i get notthing.
>
> regards
>
>[/color]
What's the Length of the SB reurned?
Did yoy try lpBuffer.ToStri ng()?
Are you sure the buffer contains a UNICODE string?
What function are you calling exactly?
Comment