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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IPC between exe and dll PLEASE HELP

Status
Not open for further replies.

ZwOOp

Programmer
Feb 15, 2005
2
0
0
SE
Hi there again all fellow programmers. I have soon finished my little helper program in C++ so that I can get on to a more familiar language (Java so that’s why I suck on pointers ;) ) and finish the project. I want to thank for all the help in this forum.



I have now get stuck on the IPC can someone please take a look at this I’m sure it is yeast some lame ass newbie error that I have done wrong.



This little C++ project is structured like this…

It has 1 .DLL file and one .EXE file they both import a .h file.

I now what to communicate between the .DLL and the .EXE file using WM_COPYDATA.



The error I get when debugging the code is [Unhandled exception in prog.exe (USER32.DLL): 0xC0000005: Access Violation]



(OBS there is more code then what is listed below but that is not of interest here)



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;



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);



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;

}



Now what access am I violating
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top