-
Notifications
You must be signed in to change notification settings - Fork 0
/
yamy.cpp
68 lines (59 loc) · 1.87 KB
/
yamy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// yamy.cpp
#include <windows.h>
#include <tchar.h>
#include "stringtool.h"
#include "mayurc.h"
/// main
int WINAPI _tWinMain(HINSTANCE i_hInstance, HINSTANCE /* i_hPrevInstance */,
LPTSTR /* i_lpszCmdLine */, int /* i_nCmdShow */)
{
typedef BOOL (WINAPI* ISWOW64PROCESS)(HANDLE hProcess, PBOOL Wow64Process);
BOOL isWow64;
ISWOW64PROCESS pIsWow64Process;
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL result;
tstring yamyPath;
_TCHAR exePath[GANA_MAX_PATH];
_TCHAR exeDrive[GANA_MAX_PATH];
_TCHAR exeDir[GANA_MAX_PATH];
GetModuleFileName(NULL, exePath, GANA_MAX_PATH);
_tsplitpath_s(exePath, exeDrive, GANA_MAX_PATH, exeDir, GANA_MAX_PATH, NULL, 0, NULL, 0);
yamyPath = exeDrive;
yamyPath += exeDir;
pIsWow64Process =
(ISWOW64PROCESS)::GetProcAddress(::GetModuleHandle(_T("kernel32.dll")),
"IsWow64Process");
ZeroMemory(&pi,sizeof(pi));
ZeroMemory(&si,sizeof(si));
si.cb=sizeof(si);
if (pIsWow64Process) {
result = pIsWow64Process(::GetCurrentProcess(), &isWow64);
if (result != FALSE && isWow64 == TRUE) {
yamyPath += _T("yamy64");
} else {
yamyPath += _T("yamy32");
}
} else {
yamyPath += _T("yamy32");
}
result = CreateProcess(yamyPath.c_str(), NULL, NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS, 0, NULL, &si, &pi);
if (result == FALSE) {
TCHAR buf[1024];
TCHAR text[1024];
TCHAR title[1024];
LoadString(i_hInstance, IDS_cannotInvoke,
text, sizeof(text)/sizeof(text[0]));
LoadString(i_hInstance, IDS_mayu,
title, sizeof(title)/sizeof(title[0]));
_stprintf_s(buf, sizeof(buf)/sizeof(buf[0]),
text, yamyPath, GetLastError());
MessageBox((HWND)NULL, buf, title, MB_OK | MB_ICONSTOP);
} else {
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
return 0;
}