Jag håller på med ett litet C++ projekt som är strukturerat såhär...Får inte WM_COPYDATA att fungera
Jag har en .DLL fil och en .EXE fil samt en .h fil som de båda importerar.
Det jag nu vill göra är att komunicera mellan .DLL och .EXE filen genom att använda WM_COPYDATA.
Det fel som uppstår när jag debuggar är: [Unhandled exception in prog.exe (USER32.DLL): 0xC0000005: Access Violation]
(OBS Nedan är ett litet kort utrag över koden som jag tror kan vara fel)
This is the code in the .h file
<code>
//The structure that I want to send to the .EXE file
typedef struct ipcMsg{
int msgType;
HWND hwnd;
TCHAR text[100];
TCHAR className[100];
HWND parenthwnd;
} *LPWM_IPCMSG;
</code>
This is the code in the .DLL file
<code>
//A shared section between the .EXE file and .DLL file
#pragma data_seg ("shared")
LPWM_IPCMSG copyDataStruct = NULL;
TCHAR textOut[MAX_TEXT_LENGTH] = {'\0'};
CWPSTRUCT *cwp = NULL;
#pragma data_seg ()
#pragma comment(linker,"/SECTION:shared,RWS")
//Then there is a function WH_CALLWNDPROC
//LPARAM in the WH_CALLWNDPROC function points to a CWPSTRUCT
cwp = (CWPSTRUCT*) lParam;
//Lets put some data in my structure (lParam is a pointer to a null terminates string that newer is longer
that 100 char)
lstrcat(copyDataStruct->text, (char*) cwp->lParam);
//Initiating the COPYDATASTRUCT that WM_COPYDATA points to, we set the data field of
COPYDATASTRUCT
//to point at the copyDataStruct and because it is placed in the shared memory space the .EXE should
have access to it (OR???)
COPYDATASTRUCT data = {0, sizeof(copyDataStruct), (PVOID) copyDataStruct};
//And then we send it away to the .EXE window
SendMessage(hObserver, WM_COPYDATA, (WPARAM) hDllInstance, (LPARAM) &data);
</code>
And finally the code in the .EXE file that import the .h file
<code>
//This code is in the WndProc function
static LPWM_IPCMSG dataCopy = NULL;
static HWND hwndList;
hwndList = CreateWindow(TEXT("listbox"), …Some stuff
switch(message)
{
case WM_COPYDATA:
//We extract the structure I want to use
dataCopy = (LPWM_IPCMSG)((COPYDATASTRUCT*)lParam)->lpData;
//and then we insert the string in the listbox by sending a pointer to a null terminated string, I use the
one in the dataCopy structure, this is actually not a
//pointer but not sure how to do this
SendMessage(hwndList[0], LB_INSERTSTRING, 0, (LPARAM) dataCopy->text);
return TRUE;
}
</code>
Varför får jag detta felet, när försöker jag läsa från fel minnesadress?