Click here to Skip to main content
15,892,537 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Named Mutex not visible from DLL Pin
Bram van Kampen12-Dec-09 16:54
Bram van Kampen12-Dec-09 16:54 
GeneralRe: Named Mutex not visible from DLL Pin
Rajesh R Subramanian12-Dec-09 18:54
professionalRajesh R Subramanian12-Dec-09 18:54 
GeneralRe: Named Mutex not visible from DLL Pin
Bram van Kampen14-Dec-09 12:25
Bram van Kampen14-Dec-09 12:25 
AnswerRe: Named Mutex not visible from DLL Pin
Richard MacCutchan12-Dec-09 1:46
mveRichard MacCutchan12-Dec-09 1:46 
GeneralRe: Named Mutex not visible from DLL Pin
Bram van Kampen12-Dec-09 16:08
Bram van Kampen12-Dec-09 16:08 
GeneralRe: Named Mutex not visible from DLL Pin
Richard MacCutchan12-Dec-09 22:55
mveRichard MacCutchan12-Dec-09 22:55 
AnswerRe: Named Mutex not visible from DLL Pin
Migounette13-Dec-09 2:36
Migounette13-Dec-09 2:36 
GeneralRe: Named Mutex not visible from DLL Pin
Bram van Kampen13-Dec-09 21:34
Bram van Kampen13-Dec-09 21:34 
Hi

Migounette wrote:
What is the goal of your mutex ?
Prevent multiple loads of the DLL or block for security reasons ?

Tell me more...


The Goal is to ensure that at most one copy each of a suite of four apps is running per machine. A function 'OnceOnly()' is exported from the DLL. So, instead of the function 'OnceOnly()' being separately included in each of the Apps, it was moved to the DLL which contains the 'Common' Code for the Apps.

The Full Code for OnceOnly() is:-
<br />
DLLEXPORT void OnceOnly(){<br />
// Protect against Two Instances on the Same Computer!<br />
        CString AppName=GetAppRootName();<br />
        CString MutexName=AppName+SG_UID;<br />
	<br />
        HANDLE exclusion = CreateMutex(NULL, FALSE, MutexName);<br />
     DWORD err = ::GetLastError();<br />
     if(err != 0){<br />
		 if(err == ERROR_ALREADY_EXISTS){<br />
			 CString Message;<br />
			 Message.Format("There is already an Instance of '%s' Running on This Computer\n\n"<br />
					 "Activate the Existing Instance instead",(LPCSTR)AppName);<br />
	    		 AfxMessageBox(Message);<br />
				 exit(0);<br />
		 }<br />
		 else{<br />
			 AfxMessageBox("An Error occurred whilst checking that No other instance of\n"<br />
				 "this program is running\n");<br />
			 exit(-1);<br />
		} // error <br />
	 }<br />


Thanks

Bram van Kampen

QuestionIm just new in c++ [modified] Pin
Amr M. K.11-Dec-09 9:32
Amr M. K.11-Dec-09 9:32 
AnswerRe: Im just new in c++ Pin
«_Superman_»11-Dec-09 9:53
professional«_Superman_»11-Dec-09 9:53 
GeneralRe: Im just new in c++ Pin
Amr M. K.11-Dec-09 9:58
Amr M. K.11-Dec-09 9:58 
GeneralRe: Im just new in c++ Pin
EliottA11-Dec-09 9:58
EliottA11-Dec-09 9:58 
QuestionRe: Im just new in c++ Pin
CPallini11-Dec-09 11:30
mveCPallini11-Dec-09 11:30 
AnswerRe: Im just new in c++ Pin
Luc Pattyn11-Dec-09 11:53
sitebuilderLuc Pattyn11-Dec-09 11:53 
GeneralRe: Im just new in c++ Pin
Amr M. K.11-Dec-09 12:31
Amr M. K.11-Dec-09 12:31 
GeneralRe: Im just new in c++ Pin
Tim Craig11-Dec-09 18:23
Tim Craig11-Dec-09 18:23 
QuestionRe: Im just new in c++ Pin
David Crow11-Dec-09 15:24
David Crow11-Dec-09 15:24 
Questiontaking a video from usb cam Pin
Asmaa Khaled FCI11-Dec-09 8:22
Asmaa Khaled FCI11-Dec-09 8:22 
AnswerRe: taking a video from usb cam Pin
loyal ginger11-Dec-09 9:33
loyal ginger11-Dec-09 9:33 
GeneralRe: taking a video from usb cam Pin
Sauce!11-Dec-09 19:09
Sauce!11-Dec-09 19:09 
AnswerRe: taking a video from usb cam Pin
Tim Craig11-Dec-09 18:26
Tim Craig11-Dec-09 18:26 
AnswerRe: taking a video from usb cam Pin
__erfan__11-Dec-09 23:09
__erfan__11-Dec-09 23:09 
Questioncover a double x to char ??? Pin
a04.lqd11-Dec-09 8:10
a04.lqd11-Dec-09 8:10 
AnswerRe: cover a double x to char ??? [modified] Pin
Luc Pattyn11-Dec-09 8:45
sitebuilderLuc Pattyn11-Dec-09 8:45 
GeneralRe: cover a double x to char ??? Pin
CPallini11-Dec-09 11:28
mveCPallini11-Dec-09 11:28 

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.