I saw an article on the Internet Article The general idea is as follows:
Tchar exefullpath [_ max_path];
Char szdrive [_ max_drive] = {0}, szdir [_ max_dir] = {0}, szfname [_ max_fname] = {0 }, szext [_ max_ext] = {0 };
Getmodulefilename (AfxGetInstanceHandle (), exefullpath, sizeof (exefullpath ));
_ Splitpath (exefullpath, szdrive, szdir, null, null );
M_strworkdir.format ("% S % s", szdrive, szdir );
Getmodulefilename can be obtainedProgramThe runtime path and file name. For more information, see msdn. however, the _ makepath and _ splitpath functions are not found on the Windows SDK (pocketpc, smartphone. h. no way. I wrote a function and obtained the path for running the program,CodeFor more information, see the following:
/*
Parameters
Hmodule:
[In] handle to the module whose executable file name is being requested.
If this parameter is null, getmodulefilename returns the path for the file used to create the calling process.
Lpfilename:
[Out] pointer to a buffer that is filled in with the path and file name of the module.
Nsize:
[In] specifies the length, in characters, of the lpfilename buffer.
If the length of the path and file name exceeds this limit, the string is truncated.
Return values
The length, in characters, of the string copied to the buffer indicates success.
Zero indicates failure.
To get extended error information, call getlasterror.
*/
DWORD getapppath (
Hmodule,
Lpwstr lpfilename,
DWORD nsize
)
{
DWORD result;
Result = getmodulefilename (null, lpfilename, nsize );
If (0 = Result ){
Return result;
}
Lpwstr PC;
PC = lpfilename + wcslen (lpfilename );
While ('//'! = * PC ){
* Pc = 0;
PC --;
}
}
Reprinted please indicate the source (http://blog.csdn.net/enjoyo)