LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing structures bet top level functions and DLL's

I need to access information stored in a structure(manipulated within a DLL)
from
the calling function. I defined the structure in the DLL include file and
#include "dll_include.h"
in the source code. The dll function manulipates the contents of the structure
as desired; however,
I can not get access to that structure from the calling function. If anyone
has any ideas, I would
certainly appreciate the help
Phil
0 Kudos
Message 1 of 2
(2,935 Views)
Hi Phil

I think the key for this problem is simply to export that structure in the
dll that you want to access from the other app.
for example if you write in your dll_include.h file something like this:

..
..
..
typedef struct
{
ULONG ID;
CHAR Name[32];
} MY_APP_PERSON,*P_MY_APP_PERSON;

typedef void (*SET_PERSON)(void);
..
..
then in your dll source write:

#include "dll_include.h"

DLLEXPORT MY_APP_PERSON DllPerson;

DLLEXPORT void SetPerson()
{
DllPerson.ID = 3;
lstrcpy(DllPerson,"Daniel A.B");
}
..
..
In your other application which uses this dll write:

#include "dll_include.h"

static P_MY_APP_PERSON AppPerson;
static SET_PERSON SetPerson;

void main()
{

HINSTANCE dllHandle;

dllHandle=LoadLibrary("Persons.dll");
if(dllHandle)
{
AppPerson=(P_MY_APP_PERSON)GetProcAddress(dllHandle,"DllPerson");
SetPerson=(SET_PERSON)GetProcAddress(dllHandle,"SetPerson");

// Watch here with the debbuger the AppPerson structure state it
will probably containt dirty data
SetPerson();
// Now watch again the value of AppPerson and see it was changed
by calling SetPerson
}
}




Phil Spratt wrote in message
news:38d02c88@newsgroups.ni.com...
>
> I need to access information stored in a structure(manipulated within a
DLL)
> from
> the calling function. I defined the structure in the DLL include file and
> #include "dll_include.h"
> in the source code. The dll function manulipates the contents of the
structure
> as desired; however,
> I can not get access to that structure from the calling function. If
anyone
> has any ideas, I would
> certainly appreciate t
he help
> Phil
0 Kudos
Message 2 of 2
(2,935 Views)