Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass a struct to and from a dll?

Status
Not open for further replies.

rbarella

Technical User
Dec 26, 2002
11
IT
or a pointer to a struct?
 
The DLL runs in the same address space as your application
So write some function in your Dll, say Give(void *);
and call this function from your applicatin after LoadLibrary call, pass your struct * to Give(void*).
 
struct __declspec(dllimport) structname
{
......
};//struct from dll

struct __declspec(dllexport) structname
{
......
};//struct to dll

__declspec(dllimport) structname xxx;
//struct instance from dll

__declspec(dllexport) structname yyy;
//struct instance to dll


Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
I'm not sure to understand.
Assuming this simple
struct MyStruct
{
int Int;
float flt;
};

and this elementary function in the dll
void DoSomething(void* pv)
{
pv->Int += 3;
pv->flt *=3.14;
}

could you please show me the full code to pass an instance of MyStruct to the dll?
I know already how to use AfxLoadLibrary and GetProcAddress: my problem is how to pass a void pointer to and fro without raising errors and/or exceptions.

Many thanks.

rbarella
 
forget about AfxLoadLibrary and GetProcAddress. When you compile a dll, you get as result a .lib and a .dll. Just compile your .exe with .lib resulted in from compiling your .dll. In .exe project use the same headers what you use in .dll.
for your exe you should declaer structure like:
struct __declspec(dllimport) MyStruct
{
int Int;
float flt;
};
for your .dll:
struct __declspec(dllexport) MyStruct
{
int Int;
float flt;
};

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top