Passing buffer to unmanaged dll.

  • Thread starter Thread starter Claire
  • Start date Start date
C

Claire

After giving up on passing nested structs to an unmanaged DLL, I planned
that I'd pass a simple buffer of bytes (the same size as the struct) to the
dll, convert to a memory stream and read in the fields from that.

I've 2 possible DLls to use, one is emulated and the other one is the "real"
one
The emulated one (that I have to use on a desktop) has a function declared
as follows in win32 delphi. The Delphi version of the code works fine for
both dlls.

The recRDetails record is 60880 bytes in size. It's fields are filled by the
dll.
{$IFDEF EMULATOR}
TdFunction = function(var recRDetails: PRDetails): integer; stdcall;
{$ELSE}
{ This is the release DLL Line }
TdFunction = function(recRDetails: PRDetails): integer; cdecl;
{$ENDIF}

I've made a dll declaration as follows. I don't know if Ive done this
correctly. Ive tried both with and without "ref" and I get a SEHexception
with both.
[DllImport(DllName, CallingConvention=CallingConvention.StdCall)]
public static extern int d86NetOpen(byte[] buffer);

I attempt to call the dll function as follows
byte[] buff = new byte[60880];
DDll.dNetOpen( buff);

Ive been fiddling with this for so long I no longer know what the hell Im
actually doing. If someone can tell me what I should be doing for both cdecl
and stdcall versions Id be very happy. (I used to understand variable types
until I came to dotnet)

thanks.
 
Claire said:
After giving up on passing nested structs to an unmanaged DLL, I planned
that I'd pass a simple buffer of bytes (the same size as the struct) to
the dll, convert to a memory stream and read in the fields from that.

I've 2 possible DLls to use, one is emulated and the other one is the
"real" one
The emulated one (that I have to use on a desktop) has a function declared
as follows in win32 delphi. The Delphi version of the code works fine for
both dlls.

The recRDetails record is 60880 bytes in size. It's fields are filled by
the dll.
{$IFDEF EMULATOR}
TdFunction = function(var recRDetails: PRDetails): integer; stdcall;
{$ELSE}
{ This is the release DLL Line }
TdFunction = function(recRDetails: PRDetails): integer; cdecl;
{$ENDIF}

I've made a dll declaration as follows. I don't know if Ive done this
correctly. Ive tried both with and without "ref" and I get a SEHexception
with both.
[DllImport(DllName, CallingConvention=CallingConvention.StdCall)]
public static extern int d86NetOpen(byte[] buffer);

I attempt to call the dll function as follows
byte[] buff = new byte[60880];
DDll.dNetOpen( buff);

Ive been fiddling with this for so long I no longer know what the hell Im
actually doing. If someone can tell me what I should be doing for both
cdecl and stdcall versions Id be very happy. (I used to understand
variable types until I came to dotnet)

thanks.

When exactly is this SEHexception thrown and what does it hold?
When passing a byte array are sure the individual elements are correctly
aligned as expected by the callee?

Willy.
 
Back
Top