Click to See Complete Forum and Search --> : passing a struct to an unmanaged dll


thegrinch
December 28th, 2006, 05:05 PM
Hi!

I am confused about the abnormal behaviour of my project.

Please consider the following situation:
I have written an application in C++.NET 2003 (managed) which loads and executes an unmanaged function from an unmanaged dll.

On the dll-side i export this function:


typedef struct {
int a;
int b;...} mystruct;

__declspec(dllexport) int dllfn(mystruct* x);

Ok.
This all compiles (and also executes, I can test this via logfiles, etc).
BUT:
If I assign values to the given struct, they "do not arrive" in the main (managed) application!!!

So, something like

x->a=17;

in the dll surprisingly does not set the value to 17 in the "real" struct allociated in the main application. On the other hand, the same instruction in the dll with

x->a=17;
printf("a: %ld", x->a);

Works!!!

I do not have any idea, why I apparently do not have access to the struct I want.


PLEASE HELP ME!

Thank you very much for your great help in advance!!!!

Kind regards!

thegrinch

thegrinch
December 29th, 2006, 09:32 AM
Another question:

By now, the dll does NOT export the struct !
Do new type definitions have to be exported into the dll?

Because, there are no errors, if both programs, the dll as well as the .net application, just use the typedefinition.
:confused: