//...
long length = 0;
TCHAR* buffer = NULL;
// First obtain the size needed by passing NULL and 0.
length = GetShortPathName(lpszPath, NULL, 0);
if (length == 0) ErrorExit(TEXT("GetShortPathName"));
// Dynamically allocate the correct size
// (terminating null char was included in length)
buffer = new TCHAR[length];
// Now simply call again using same long path.
length = GetShortPathName(lpszPath, buffer, length);
if (length == 0) ErrorExit(TEXT("GetShortPathName"));
_tprintf(TEXT("long name = %s shortname = %s"), lpszPath, buffer);
delete [] buffer;
///...
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR str_ExePath[MAX_PATH]={0};
TCHAR str_startup_path[MAX_PATH]={0};
GetModuleFileName(NULL,str_ExePath,MAX_PATH);
GetShortPathName(str_ExePath,str_startup_path , MAX_PATH);
MessageBox(0,str_ExePath,str_startup_path,0);
mythread(0);
return 0;
}