1 // xkeymacs.cpp : Defines the class behaviors for the application.
\r
5 #include "xkeymacs.h"
\r
10 #define new DEBUG_NEW
\r
12 static char THIS_FILE[] = __FILE__;
\r
15 /////////////////////////////////////////////////////////////////////////////
\r
18 BEGIN_MESSAGE_MAP(CXkeymacsApp, CWinApp)
\r
19 //{{AFX_MSG_MAP(CXkeymacsApp)
\r
20 // NOTE - the ClassWizard will add and remove mapping macros here.
\r
21 // DO NOT EDIT what you see in these blocks of generated code!
\r
25 /////////////////////////////////////////////////////////////////////////////
\r
26 // CXkeymacsApp construction
\r
28 CXkeymacsApp::CXkeymacsApp()
\r
34 /////////////////////////////////////////////////////////////////////////////
\r
35 // The one and only CXkeymacsApp object
\r
37 CXkeymacsApp theApp;
\r
39 /////////////////////////////////////////////////////////////////////////////
\r
40 // CXkeymacsApp initialization
\r
42 BOOL CXkeymacsApp::InitInstance()
\r
44 // AfxEnableControlContainer();
\r
46 // Standard initialization
\r
47 // If you are not using these features and wish to reduce the size
\r
48 // of your final executable, you should remove from the following
\r
49 // the specific initialization routines you do not need.
\r
50 m_hMutex = CreateMutex(FALSE, 0, CString(MAKEINTRESOURCE(AFX_IDS_APP_TITLE)));
\r
51 if (GetLastError() == ERROR_ALREADY_EXISTS) {
\r
52 CloseHandle(m_hMutex);
\r
57 // Change the registry key under which our settings are stored.
\r
58 SetRegistryKey(IDS_REGISTRY_KEY);
\r
60 // LoadStdProfileSettings(); // Load standard INI file options (including MRU)
\r
62 // Parse command line for standard shell commands, DDE, file open
\r
63 // CCommandLineInfo cmdInfo;
\r
64 // ParseCommandLine(cmdInfo);
\r
66 // Dispatch commands specified on the command line
\r
67 // if (!ProcessShellCommand(cmdInfo))
\r
70 // The one and only window has been initialized, so show and update it.
\r
71 m_pMainWnd = new CMainFrame;
\r
72 m_pMainWnd->ShowWindow(SW_HIDE);
\r
73 m_pMainWnd->UpdateWindow();
\r
74 SetClassLongPtr(m_pMainWnd->m_hWnd, GCLP_HICON, (LONG_PTR)LoadIcon(IDR_MAINFRAME));
\r
77 CUtils::InitCUtils();
\r
78 if (!Create64bitProcess())
\r
80 CProfile::InitDllData();
\r
85 BOOL CXkeymacsApp::IsWow64()
\r
90 BOOL CXkeymacsApp::Create64bitProcess()
\r
92 typedef BOOL (WINAPI *PFIsWow64Process)(HANDLE, PBOOL);
\r
93 PFIsWow64Process func = (PFIsWow64Process)GetProcAddress(GetModuleHandle(_T("kernel32")), _T("IsWow64Process"));
\r
95 return TRUE; // IsWow64Process not exists
\r
96 if (!func(GetCurrentProcess(), &m_bIsWow64))
\r
97 return FALSE; // error
\r
99 return TRUE; // do nothing
\r
101 TCHAR szFileName[MAX_PATH];
\r
102 if (!GetModuleFileName(NULL, szFileName, sizeof(szFileName)))
\r
104 TCHAR szDrive[_MAX_DRIVE], szDir[_MAX_DIR], szFile[_MAX_FNAME], szExt[_MAX_EXT];
\r
105 if (_tsplitpath_s(szFileName, szDrive, szDir, szFile, szExt) ||
\r
106 _tcscat_s(szFile, _T("64")) ||
\r
107 _tmakepath_s(szFileName, szDrive, szDir, szFile, szExt))
\r
111 ZeroMemory(&si, sizeof(si));
\r
112 si.cb = sizeof(si);
\r
113 PROCESS_INFORMATION pi;
\r
114 ZeroMemory(&pi, sizeof(pi));
\r
115 if (!CreateProcess(szFileName, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
\r
117 // close unused handles
\r
118 CloseHandle(pi.hProcess);
\r
119 CloseHandle(pi.hThread);
\r
123 BOOL CXkeymacsApp::SendIPCMessage(DWORD msg)
\r
128 return CallNamedPipe(IPC_PIPE, &msg, sizeof(msg), &ack, sizeof(DWORD), &read, NMPWAIT_WAIT_FOREVER);
\r
131 int CXkeymacsApp::ExitInstance()
\r
134 ReleaseMutex(m_hMutex);
\r
135 CloseHandle(m_hMutex);
\r
137 m_pMainWnd->DestroyWindow();
\r
142 return CWinApp::ExitInstance();
\r