1 | #include "stdafx.h" |
---|
2 | #include <shlwapi.h> |
---|
3 | |
---|
4 | int _tmain(int argc, _TCHAR* argv[]) |
---|
5 | { |
---|
6 | TCHAR pszPath[1024] = { 0 }; |
---|
7 | ATLVERIFY(GetModuleFileName(NULL, pszPath + 4, _countof(pszPath) - 4)); |
---|
8 | ATLVERIFY(PathRemoveFileSpec(pszPath + 4)); |
---|
9 | pszPath[0] = _T('\\'); |
---|
10 | pszPath[1] = _T('\\'); |
---|
11 | pszPath[2] = _T('?'); |
---|
12 | pszPath[3] = _T('\\'); |
---|
13 | static const LPCTSTR g_pszSubdirectory = _T("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); |
---|
14 | _tcscat_s(pszPath, _T("\\")); |
---|
15 | _tcscat_s(pszPath, g_pszSubdirectory); |
---|
16 | _tcscat_s(pszPath, _T("\\")); |
---|
17 | _tcscat_s(pszPath, _T("GetModuleFileName01.exe")); |
---|
18 | _tprintf(_T("Path: (%d) %s\n"), _tcslen(pszPath), pszPath); |
---|
19 | STARTUPINFO StartupInfo; |
---|
20 | ZeroMemory(&StartupInfo, sizeof StartupInfo); |
---|
21 | StartupInfo.cb = sizeof StartupInfo; |
---|
22 | PROCESS_INFORMATION ProcessInformation; |
---|
23 | BOOL bResult = CreateProcess(pszPath, NULL, NULL, NULL, TRUE, 0, NULL, NULL, &StartupInfo, &ProcessInformation); |
---|
24 | if(!bResult) |
---|
25 | { |
---|
26 | const DWORD nLastError = GetLastError(); |
---|
27 | _tprintf(_T("Error: %d\n"), nLastError); |
---|
28 | if(nLastError != ERROR_INSUFFICIENT_BUFFER) |
---|
29 | return 1; |
---|
30 | TCHAR pszShortPath[MAX_PATH] = { 0 }; |
---|
31 | ATLVERIFY(GetShortPathName(pszPath, pszShortPath, _countof(pszShortPath))); |
---|
32 | _tprintf(_T("Short Path: (%d) %s\n"), _tcslen(pszShortPath), pszShortPath); |
---|
33 | bResult = CreateProcess(pszShortPath, NULL, NULL, NULL, TRUE, 0, NULL, NULL, &StartupInfo, &ProcessInformation); |
---|
34 | } |
---|
35 | ATLASSERT(bResult); |
---|
36 | ATLVERIFY(CloseHandle(ProcessInformation.hThread)); |
---|
37 | ATLVERIFY(CloseHandle(ProcessInformation.hProcess)); |
---|
38 | return 0; |
---|
39 | } |
---|
40 | |
---|
41 | /* |
---|
42 | |
---|
43 | Win32: |
---|
44 | |
---|
45 | Path: (279) \\?\D:\Projects\Alax.Info\Repository-Public\Utilities\Miscellaneous\GetModuleFileName01\_Bin\Win32\Debug\123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\GetModuleFileName01.exe |
---|
46 | Error: 122 |
---|
47 | Short Path: (101) \\?\D:\Projects\ALAX~1.INF\REPOSI~2\UTILIT~1\MISCEL~1\GETMOD~1\_Bin\Win32\Debug\123456~1\GETMOD~1.EXE |
---|
48 | (101) \\?\D:\Projects\ALAX~1.INF\REPOSI~2\UTILIT~1\MISCEL~1\GETMOD~1\_Bin\Win32\Debug\123456~1\GETMOD~1.EXE |
---|
49 | (101) \\?\D:\Projects\ALAX~1.INF\REPOSI~2\UTILIT~1\MISCEL~1\GETMOD~1\_Bin\Win32\Debug\123456~1\GETMOD~1.EXE |
---|
50 | |
---|
51 | x64: |
---|
52 | |
---|
53 | Path: (277) \\?\D:\Projects\Alax.Info\Repository-Public\Utilities\Miscellaneous\GetModuleFileName01\_Bin\x64\Debug\123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\GetModuleFileName01.exe |
---|
54 | (259) \\?\D:\Projects\Alax.Info\Repository-Public\Utilities\Miscellaneous\GetModuleFileName01\_Bin\x64\Debug\123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\GetMo |
---|
55 | (277) \\?\D:\Projects\Alax.Info\Repository-Public\Utilities\Miscellaneous\GetModuleFileName01\_Bin\x64\Debug\123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\GetModuleFileName01.exe |
---|
56 | |
---|
57 | */ |
---|