Exporting a struct from a DLL
-
Hi guys, Is it possible to export a structure from a dll without including the header file where the structure is define? For example:
/*-------------------------
mydllheader.h
------------------------------*/extern "C" __declspec(dllexport) struct MyStruct
{MyStruct() { a = 0; b = 0; } int a; int b;
}
Instead of including mydllheader.h I want to do the following:
/*-------------------------
myimportheader.h
------------------------------*/extern "C" __declspec(dllimport) struct MyStruct
I would like to use myimportheader.h in my projects that use the dll that way I can hide my structure implementation from the user. Is that possible? Thanks.
-
Hi guys, Is it possible to export a structure from a dll without including the header file where the structure is define? For example:
/*-------------------------
mydllheader.h
------------------------------*/extern "C" __declspec(dllexport) struct MyStruct
{MyStruct() { a = 0; b = 0; } int a; int b;
}
Instead of including mydllheader.h I want to do the following:
/*-------------------------
myimportheader.h
------------------------------*/extern "C" __declspec(dllimport) struct MyStruct
I would like to use myimportheader.h in my projects that use the dll that way I can hide my structure implementation from the user. Is that possible? Thanks.
You could do it this way but what is the point? If you hide everything from the user then what purpose is served by the structure? A better solution is to create a class that has methods but hides all variables and implementation details.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
-
Hi guys, Is it possible to export a structure from a dll without including the header file where the structure is define? For example:
/*-------------------------
mydllheader.h
------------------------------*/extern "C" __declspec(dllexport) struct MyStruct
{MyStruct() { a = 0; b = 0; } int a; int b;
}
Instead of including mydllheader.h I want to do the following:
/*-------------------------
myimportheader.h
------------------------------*/extern "C" __declspec(dllimport) struct MyStruct
I would like to use myimportheader.h in my projects that use the dll that way I can hide my structure implementation from the user. Is that possible? Thanks.
Not if the user of your dll creates instances of MyStruct itself. It needs to be a complete type if the user of your DLL is to create instances of it. If you delegate all creation/destruction of MyStruct instances to the dll, you can achieve something like this. I've seen this sort of thing done with void *'s for the interface. I don't know if you could do this with a pointer to an incomplete type. If not, you could get a sort of type safety by wrapping the void * in a struct of its own with the definition of that struct exposed to the consuming application.
Please do not read this signature.