I have a simple application with 1 button to know if Notepadd++ is already open. I have review some topics but I cannot find the right one. Inside the button method I have:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
mutex = CreateMutex( NULL, TRUE, "Local\\$notepad++$");
if (GetLastError() == ERROR_ALREADY_EXISTS) {
//MessageBox::Show(..[not open]..);
}
//MessageBox::Show(..[open]..);
}
};
I have a problem with "Local\$notepad++$", I get this errors:
argument of type "const char *" is incompatible with parameter of type "LPCWSTR"
and this other:
'HANDLE CreateMutexW(LPSECURITY_ATTRIBUTES,BOOL,LPCWSTR)': cannot convert argument 3 from 'const char [18]' to 'LPCWSTR'
If there is another easier way to do this please help me! I have also try changing the name to: notepad++. I am using visual studio 2015 c++
I have review and use as reference:
C/C++ How to tell if a program is already running?
Is using a Mutex to prevent multiple instances of the same program from running safe?