473,382 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Passing buffer to unmanaged dll.

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.
Nov 16 '05 #1
2 2498
s'ok I fixed it. There was a problem with the emulator dll itself.
Nov 16 '05 #2

"Claire" <cc@hotmai1.com> wrote in message
news:3a*************@individual.net...
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.
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mick | last post by:
Does anyone know how to pass an array of structures to a DLL? Here's what I'm doing... the VB.Net error is at the end. *** C++ Structure Declaration: typedef struct _SOME_STRUCT { char...
3
by: Sam Carleton | last post by:
I am writing Managed C++ code to call in to an Unmanaged C API. The reason for using Managed C++ over C# is that the Unmanaged C module is loaded via LoadLibrary(). DllImport cannot be used;...
0
by: Lonewolf | last post by:
Hi, I'm not sure if this has been asked before so please pardon me if this is a repeated question. Basically I have some performance critical directshow codes which is implemented in native,...
4
by: Joe Tavares | last post by:
I have a dll that takes a byte pointer. Similar to this: writeDataToBuffer(byte *buffer, int *BufferSize); The buffer is allocated by the dll. I have no problem with the BufferSize parameter...
4
by: Greg Young | last post by:
Ok so I think everyone can agree that creating buffers on the fly in an async socket server is bad ... there is alot of literature available on the problems this will cause with the heap. I am...
0
by: firstquestion | last post by:
Hello, I need to pass a StringBuilder object to a custom unmanaged DLL. The code most of the time works great, however once in a while I get "Object reference not set to an instance of an object"...
13
by: Creativ | last post by:
I've looked through this thread and still have quetions. Suppose In visual studio 2005, I write the following #pragam managed class ManagedWrapper { void CallUnmanagedMethod() // The unmanaged...
2
by: =?Utf-8?B?QmFydE1hbg==?= | last post by:
Greetings, I am working on a project where the interface from the UI application (done in C#) requires that an image buffer be passed back as a byte array as defined by an interface. The...
13
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper in C# for an SDK that has been supplied as a .LIB file and a .h header file. I have got most of the functions to work but am really struggling with the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.