#include "xkeymacs.h"\r
#include "profile.h"\r
#include "../xkeymacsdll/xkeymacsdll.h"\r
+#include "../xkeymacsdll/Utils.h"\r
\r
#ifdef _DEBUG\r
#define new DEBUG_NEW\r
bool SendAck(HANDLE pipe)\r
{\r
DWORD written, ack = 0;\r
- return WriteFile(pipe, &ack, sizeof(DWORD), &written, NULL) && written == sizeof(DWORD) &&\r
- FlushFileBuffers(pipe) && DisconnectNamedPipe(pipe);\r
+ if (!WriteFile(pipe, &ack, sizeof(DWORD), &written, NULL) && written != sizeof(DWORD)) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("SendAck: WriteFile failed. (%d)"), GetLastError());\r
+#endif\r
+ return false;\r
+ }\r
+ if (!FlushFileBuffers(pipe)) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("SendAck: FlushFileBuffers failed. (%d)"), GetLastError());\r
+#endif\r
+ return false;\r
+ }\r
+ if (!DisconnectNamedPipe(pipe)) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("SendAck: DisconnectNamedPipe failed. (%d)"), GetLastError());\r
+#endif\r
+ return false;\r
+ }\r
+ return true;\r
}\r
\r
DWORD WINAPI CMainFrame::PollMessage(LPVOID)\r
{\r
HANDLE pipe = CreateNamedPipe(XKEYMACS32_PIPE, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, 1,\r
sizeof(DWORD), sizeof(IPC32Message), 0, NULL);\r
- if (pipe == INVALID_HANDLE_VALUE)\r
+ if (pipe == INVALID_HANDLE_VALUE) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("PollMessage: CreateNamedPipe failed. (%d)"), GetLastError());\r
+#endif\r
return 1;\r
+ }\r
for (; ;) {\r
- if (ConnectNamedPipe(pipe, NULL) ? FALSE : (GetLastError() != ERROR_PIPE_CONNECTED))\r
+ if (ConnectNamedPipe(pipe, NULL) ? FALSE : (GetLastError() != ERROR_PIPE_CONNECTED)) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("PollMessage: ConnectNamedPipe failed. (%d)"), GetLastError());\r
+#endif\r
break;\r
+ }\r
IPC32Message msg;\r
DWORD read;\r
- if (!ReadFile(pipe, &msg, sizeof(msg), &read, NULL))\r
+ if (!ReadFile(pipe, &msg, sizeof(msg), &read, NULL)) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("PollMessage: ReadFile failed. (%d)"), GetLastError());\r
+#endif\r
break;\r
+ }\r
switch (msg.Type) {\r
case IPC32_TERMINATE:\r
SendAck(pipe);\r
#include "xkeymacs.h"\r
#include "mainfrm.h"\r
#include "profile.h"\r
+#include "../xkeymacsdll/Utils.h"\r
\r
#ifdef _DEBUG\r
#define new DEBUG_NEW\r
DWORD ack, read;\r
for (int i = 0; i < 10; Sleep(100), ++i)\r
if (CallNamedPipe(XKEYMACS64_PIPE, &msg, sizeof(msg), &ack, sizeof(DWORD), &read, NMPWAIT_WAIT_FOREVER))\r
- return;;\r
+ return;\r
+#ifdef DEBUG_IPC\r
+ else\r
+ CUtils::Log(_T("SendIPC64Message: CallNamedPipe failed. (%d)"), GetLastError());\r
+#endif\r
}\r
\r
int CXkeymacsApp::ExitInstance() \r
#include "xkeymacs64.h"\r
#include "mainfrm64.h"\r
#include "../xkeymacsdll/xkeymacsdll.h"\r
+#include "../xkeymacsdll/Utils.h"\r
\r
CXkeymacsApp::CXkeymacsApp()\r
{\r
return TRUE;\r
}\r
\r
+bool SendAck(HANDLE pipe)\r
+{\r
+ DWORD written, ack = 0;\r
+ if (!WriteFile(pipe, &ack, sizeof(DWORD), &written, NULL) && written != sizeof(DWORD)) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("SendAck: WriteFile failed. (%d)"), GetLastError());\r
+#endif\r
+ return false;\r
+ }\r
+ if (!FlushFileBuffers(pipe)) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("SendAck: FlushFileBuffers failed. (%d)"), GetLastError());\r
+#endif\r
+ return false;\r
+ }\r
+ if (!DisconnectNamedPipe(pipe)) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("SendAck: DisconnectNamedPipe failed. (%d)"), GetLastError());\r
+#endif\r
+ return false;\r
+ }\r
+ return true;\r
+}\r
+\r
UINT PollIPCMessage(LPVOID param)\r
{\r
HANDLE hPipe = CreateNamedPipe(XKEYMACS64_PIPE, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, 1, 512, 512, 0, NULL);\r
- if (hPipe == INVALID_HANDLE_VALUE)\r
+ if (hPipe == INVALID_HANDLE_VALUE) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("PollIPCMessage: CreateNamedPipe failed. (%d)"), GetLastError());\r
+#endif\r
return 1;\r
+ }\r
for (; ;) {\r
- if (ConnectNamedPipe(hPipe, NULL) ? FALSE : (GetLastError() != ERROR_PIPE_CONNECTED))\r
+ if (ConnectNamedPipe(hPipe, NULL) ? FALSE : (GetLastError() != ERROR_PIPE_CONNECTED)) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("PollIPCMessage: ConnectNamedPipe failed. (%d)"), GetLastError());\r
+#endif\r
break;\r
+ }\r
DWORD msg;\r
DWORD read;\r
- if (!ReadFile(hPipe, &msg, sizeof(msg), &read, NULL) || read != sizeof(msg)) \r
+ if (!ReadFile(hPipe, &msg, sizeof(msg), &read, NULL) || read != sizeof(msg)) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("PollIPCMessage: ReadFile failed. (%d)"), GetLastError());\r
+#endif\r
break;\r
+ }\r
switch (msg)\r
{\r
case IPC64_EXIT:\r
CXkeymacsDll::SetHookStateDirect(true);\r
break;\r
}\r
- DWORD written, ack = 0;\r
- if (!WriteFile(hPipe, &ack, sizeof(DWORD), &written, NULL) || written != sizeof(DWORD)\r
- || !FlushFileBuffers(hPipe) || !DisconnectNamedPipe(hPipe))\r
- break;\r
+ SendAck(hPipe);\r
}\r
exit:\r
CloseHandle(hPipe);\r
IPC32Message msg;\r
msg.Type = IPC32_HOOKSTATE;\r
msg.Enable = enable;\r
- CallNamedPipe(XKEYMACS32_PIPE, &msg, offsetof(IPC32Message, Enable) + sizeof(bool), &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT);\r
+ if (!CallNamedPipe(XKEYMACS32_PIPE, &msg, offsetof(IPC32Message, Enable) + sizeof(bool), &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT))\r
+ CUtils::Log(_T("SetHookState: CallNamedPipe failed. (%d)"), GetLastError());\r
\r
ShowHookState();\r
}\r
IPC32Message msg;\r
msg.Type = IPC32_ICON;\r
memcpy(msg.IconState, state, num * sizeof(IconState));\r
- CallNamedPipe(XKEYMACS32_PIPE, &msg, offsetof(IPC32Message, IconState) + sizeof(IconState) * num, &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT);\r
+ if (!CallNamedPipe(XKEYMACS32_PIPE, &msg, offsetof(IPC32Message, IconState) + sizeof(IconState) * num, &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT)) {\r
+#ifdef DEBUG_IPC\r
+ CUtils::Log(_T("SendIconMessage: CallNamedPipe failed. (%d)"), GetLastError());\r
+#endif\r
+ }\r
}\r
\r
void CXkeymacsDll::Kdu(BYTE bVk, DWORD n, BOOL bOriginal)\r