I call GetModuleFileName
function, in order to retrieve the fully qualified path of a specified module, in order to call another .exe in the same file, via Process::Start
method.
However, .exe cannot be called when the path contains other than Latin characters (in my case Greek characters).
Is there any way I can fix this?
Code:
TCHAR path[1000];
GetModuleFileName(NULL, path, 1000) ; // Retrieves the fully qualified path for the file that
// contains the specified module.
PathRemoveFileSpec(path); // Removes the trailing file name and backslash from a path (TCHAR).
CHAR mypath[1000];
// Convert TCHAR to CHAR.
wcstombs(mypath, path, wcslen(path) + 1);
// Formatting the string: constructing a string by substituting computed values at various
// places in a constant string.
CHAR mypath2[1000];
sprintf_s(mypath2, "%s\\Client_JoypadCodesApplication.exe", mypath);
String^ result;
result = marshal_as<String^>(mypath2);
Process::Start(result);
Strings in .NET are encoded in UTF-16. The fact that you are calling
wcstombs()
means your app is compiled for Unicode andTCHAR
maps toWCHAR
, which is what Windows uses for UTF-16. So there is no need to callwcstombs()
at all. Retrieve and format the path as UTF-16, then marshal it as UTF-16. Stop usingTCHAR
altogether (unless you need to compile for Windows 9x/ME):A better option would be to use a native .NET solution instead (untested):