Click here to Skip to main content
15,898,134 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhex values to words Pin
flippydeflippydebop2-Jan-07 23:37
flippydeflippydebop2-Jan-07 23:37 
AnswerRe: hex values to words Pin
Christian Graus3-Jan-07 0:23
protectorChristian Graus3-Jan-07 0:23 
GeneralRe: hex values to words Pin
flippydeflippydebop3-Jan-07 0:43
flippydeflippydebop3-Jan-07 0:43 
GeneralRe: hex values to words Pin
flippydeflippydebop3-Jan-07 1:48
flippydeflippydebop3-Jan-07 1:48 
QuestionRe: hex values to words Pin
David Crow3-Jan-07 5:35
David Crow3-Jan-07 5:35 
AnswerRe: hex values to words Pin
flippydeflippydebop4-Jan-07 0:38
flippydeflippydebop4-Jan-07 0:38 
GeneralRe: hex values to words Pin
David Crow4-Jan-07 3:24
David Crow4-Jan-07 3:24 
Question"synchronized" method call in dll Pin
trumper2-Jan-07 23:21
trumper2-Jan-07 23:21 
Hi, I am trying to write a "synchronized" function call in my dll so that programmers that use my api can expect to only make single-instance function calls. The basic motivation is that each function call spawns a thread hence I would like to greatly restrict the number of threads spawned (basically 1-and-only-1 thread spawn per function call to my api).

//In my program.h header file
int threadCode = 0; //no problem if threadCode is instantiated in the header file
HANDLE threadMutexEvent;
#define PROC_THREAD 0
#define ERR_THREAD_INUSE 1

//In my program.cpp program file
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
//problem arises if I instantiate threadCode here
//threadCode = 0;

threadMutexEvent = CreateEvent(NULL, false, true, "MutexEvent");
return true;
}

int WINAPI processRequest() {
WaitForSingleObject(threadMutexEvent, INFINITE);
if(threadCode == PROC_THREAD) {
threadCode = ERR_THREAD_INUSE;
SetEvent(threadMutexEvent);
} else {
SetEvent(threadMutexEvent);
return ERR_THREAD_INUSE;
}

//spawn thread to do some work for me
return 0;
}

As you can see, I am using Win32's synchronization mechanism to do some simple synchronization on the global variable threadCode. As seen in the code comments listed above, everything is fine if I instantiate threadCode in the header file, however, once I shift the instantiation of threadCode to DllMain the synchronization gets messed up. Basically, seperate function calls to processRequest would always "see" threadCode == PROC_THREAD and go ahead to spawn another thread (which is what I am trying to prevent Frown | :(

If all things fail I would fall back on leaving the instantiation in the header file, but I am really curious as to why the 2 seemingly identical instantiation calls would result in 2 drastically different results.

Thanks
AnswerRe: "synchronized" method call in dll Pin
David Leyva3-Jan-07 6:54
David Leyva3-Jan-07 6:54 
GeneralRe: "synchronized" method call in dll Pin
trumper3-Jan-07 15:02
trumper3-Jan-07 15:02 
GeneralRe: "synchronized" method call in dll Pin
David Leyva3-Jan-07 18:19
David Leyva3-Jan-07 18:19 
AnswerRe: "synchronized" method call in dll Pin
David Leyva3-Jan-07 18:23
David Leyva3-Jan-07 18:23 
GeneralRe: "synchronized" method call in dll Pin
trumper4-Jan-07 16:13
trumper4-Jan-07 16:13 
Questioni want to read that file Pin
naveen padiyar2-Jan-07 20:41
naveen padiyar2-Jan-07 20:41 
Jokeü'" "' " (It's simple) Pin
<color>Aljechin 2-Jan-07 21:35
<color>Aljechin 2-Jan-07 21:35 
GeneralRe: ü'" "' " (It's simple) Pin
Hamid_RT3-Jan-07 1:18
Hamid_RT3-Jan-07 1:18 
GeneralRe: ü'" "' " (It's simple) Pin
Mark Salsbery3-Jan-07 7:07
Mark Salsbery3-Jan-07 7:07 
GeneralRe: ü'" "' " (It's simple) Pin
Hamid_RT3-Jan-07 17:41
Hamid_RT3-Jan-07 17:41 
GeneralRe: ü'" "' " (It's simple) Pin
naveen padiyar4-Jan-07 20:09
naveen padiyar4-Jan-07 20:09 
QuestionHow to create a .dat file Pin
poda2-Jan-07 20:28
poda2-Jan-07 20:28 
AnswerRe: How to create a .dat file Pin
Christian Graus2-Jan-07 22:17
protectorChristian Graus2-Jan-07 22:17 
GeneralRe: How to create a .dat file Pin
poda2-Jan-07 23:11
poda2-Jan-07 23:11 
GeneralRe: How to create a .dat file Pin
Joan M3-Jan-07 1:30
professionalJoan M3-Jan-07 1:30 
AnswerRe: How to create a .dat file Pin
Daniel Kanev2-Jan-07 23:18
Daniel Kanev2-Jan-07 23:18 
GeneralRe: How to create a .dat file Pin
poda3-Jan-07 21:29
poda3-Jan-07 21:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.