473,779 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(recRDe tails: 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(DllNa me, CallingConventi on=CallingConve ntion.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 2522
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******** *****@individua l.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(recRDe tails: 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(DllNa me, CallingConventi on=CallingConve ntion.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
16851
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 *pId; char *pBuffer;
3
3560
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; functions pointers and GetProcAddress() is being used. The API function definition looks like this: int GetString( char* pszOutStr, int *nStrLen) It looks like the prototyping of the function pointer is straight
0
327
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, unmanaged C++. I have written a managed wrapper for it using C++/CLI. problem comes when I try to pass a C# string over to the DLL via C++/CLO. Basically I have a textbox in the C# GUI, and I declared my C++/CLI property as follows. C++/CLI property...
4
5261
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 it is the buffer parameter that I am not sure of the best way to handle. What is the recommended way to call this function from C#?
4
3560
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 looking at a few options to get around this. 1) Have a BufferPool class that hands out ArraySegment<byteportions of a larger array (large enough that it would be in the LOH). If all of the array is used create another big segment. 2) Create a...
0
1885
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" which means the GC moved the address of StringBuilder object while managed code is writing to it. I have tried GC.keepalive already. GCHandle.allc and Marshal.alloc doesn't seem to be possible with this type of object. I need the equivalent of ...
13
2882
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 class /method is imported from a C++ DLL generated by vc 6.0 { std::string* inputString = new string();
2
3599
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 problem is that the device uses a legacy c style buffer of unsigned char* to hold its image data. I wrote a C++\Clr wrapper around the legacy c stuff. Which is working really well with other features of the device.
13
3207
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 functions that require a structure to be passed to them. The function declaration in the .h file is of the form: SDCERR GetConfig(char *name, SDCConfig *cfg); where SDCConfig is a structure defined in the .h file. I am not much of a C (or C#)...
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.