
Transfer data members from .exe to .dll
Claude,
Create a var structure based upon the information you wish to transfer. Make
sure that both programs have #include'd the header file describing the
structure. Pass a pointer to the structure into your .DLL exported function.
Recommended: do not use C++ style vars (i.e. CString, COleDateTime, etc)
except as Read Only within the .DLL. Best to stick to standard C styles such
as BYTE, CHAR, WCHAR, int, long, short, etc.
Quick example:
/* the structure from a common header file*/
typedef struct tagMYINFO
{
char mystring[UNLEN];
int mynumber;
DWORD mysysdate;
Quote:
}MYINFO, *PMYINFO, FAR *LPMYINFO;
/* the EXE function */
void MyExeFunc(void)
{
LPMYINFO lpMyInfo = new MYINFO;
strcpy(lpMyInfo->mystring, "This is my string");
lpMyInfo->mynumber = 128;
lpMyInfo->mysysdate = 10000001;
MyDllFunc(lpMyInfo);
return;
Quote:
}
/* the DLL function */
void WINAPI MyDllFunc(LPMYINFO lpMyOwnInfo)
{
char Mssg[UNLEN + 64]; // big enough to handle 'mystring' and some for the
others
sprintf(Mssg, "%s\nMy number is %d\nMy numerical sys date is %lu",
lpMyOwnInfo->mystring, lpMyOwnInfo->mynumber, lpMyOwnInfo->mysysdate);
MessagerBox(Getfocus(), Mssg, "My values", MB_OK|MB_ICONINFORMATION);
return;
Quote:
}
Hmmm... I think I got those right. Remember to export the function in the
DLL, include the LIB file, and use the C wrapper in the import/export
declarations.
Dennis Pugh
Quote:
>Hi,
>I have an application with numerous data members.
>I have to write a DLL to do all the calculations required by my
>application.
>How can I have access to the data members from the CMyClassView.cpp in
>the DLL implementation ? I want to have access by another method than
>as arguments pass in a function.
> Thanks for any help.
> Claude Gagnon