M
matt
Hi All,
I'm trying to write a windows service by modifying an example I found
at http://www.thecodeproject.com
This is my first encounter with a multithreaded app so please forgive
this newbie question but I'm having a little bit of difficulty using
global variables inside the threads
The code basically looks like this
HANDLE killServiceEvent;
HANDLE hGinaThread, hTrayIconThread;
char * szPinNumber;
void main() {
DWORD idGina, idTrayIcon;
hGinaThread=CreateThread(0,0,(LPTHREAD_START_ROUTINE)GinaThread,0,0,&idGina);
hTrayIconThread=CreateThread(0,0,(LPTHREAD_START_ROUTINE)TrayIconThread,0,0,&idTrayIcon);
WaitForSingleObject(killServiceEvent,INFINITE);
CloseHandle(killServiceEvent);
}
DWORD GinaThread(LPDWORD param) {
//Code gets pin number from a mailslot
szPinNumber = szMailslotData;
return 0;
}
DWORD TrayIconThread(LPDWORD param) {
Sleep(120000);
MessageBox(NULL, szPinNumber, NULL, MB_OK);
return 0;
}
The program just crashes when it tries to display the MessageBox.
However if I change the code slightly by changing the declaration of
szPinNumber to char * szPinNumber = "PIN Number"; and comment out the
line in GinaThread that updates szPinNumber the code executes
flawlessly.
Any ideas?
I'm trying to write a windows service by modifying an example I found
at http://www.thecodeproject.com
This is my first encounter with a multithreaded app so please forgive
this newbie question but I'm having a little bit of difficulty using
global variables inside the threads
The code basically looks like this
HANDLE killServiceEvent;
HANDLE hGinaThread, hTrayIconThread;
char * szPinNumber;
void main() {
DWORD idGina, idTrayIcon;
hGinaThread=CreateThread(0,0,(LPTHREAD_START_ROUTINE)GinaThread,0,0,&idGina);
hTrayIconThread=CreateThread(0,0,(LPTHREAD_START_ROUTINE)TrayIconThread,0,0,&idTrayIcon);
WaitForSingleObject(killServiceEvent,INFINITE);
CloseHandle(killServiceEvent);
}
DWORD GinaThread(LPDWORD param) {
//Code gets pin number from a mailslot
szPinNumber = szMailslotData;
return 0;
}
DWORD TrayIconThread(LPDWORD param) {
Sleep(120000);
MessageBox(NULL, szPinNumber, NULL, MB_OK);
return 0;
}
The program just crashes when it tries to display the MessageBox.
However if I change the code slightly by changing the declaration of
szPinNumber to char * szPinNumber = "PIN Number"; and comment out the
line in GinaThread that updates szPinNumber the code executes
flawlessly.
Any ideas?