Skip to content

Commit eb9cafe

Browse files
committed
优化 可在没安装电脑管家的情况下运行
1 parent cc85556 commit eb9cafe

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

MateBook-E-Pen.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "framework.h"
22
#include "MateBook-E-Pen.h"
33

4-
#define version "2.1.0"
5-
#define dev_mode false
4+
#define version "2.1.1"
5+
#define dev_mode true
66

77
/////////////////////////////////////////////
88
///////////////// /////////////////
@@ -22,9 +22,25 @@ void init(HWND hWnd)
2222
hDll_PenService = LoadLibrary(L"C:\\Program Files\\Huawei\\PCManager\\components\\accessories_center\\accessories_app\\AccessoryApp\\Lib\\Plugins\\Depend\\PenService.dll");
2323
if (hDll_PenService == NULL)
2424
{
25-
MessageBox(hWnd, L"请检查华为电脑管家和手写笔相关驱动是否正确安装!", L"出错啦!", MB_OK);
26-
SendMessage(hWnd, WM_CLOSE, 0, 0);
27-
return;
25+
HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(IDR_DLL1), L"DLL");
26+
DWORD dwSize = SizeofResource(hInst, hRes);
27+
HGLOBAL hGlob = LoadResource(hInst, hRes);
28+
void* pRes = LockResource(hGlob);
29+
wchar_t szPath[MAX_PATH];
30+
GetTempPath(MAX_PATH, szPath);
31+
wcscat_s(szPath, L"PenService.dll");
32+
HANDLE hFile = CreateFile(szPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
33+
DWORD dwWrite;
34+
WriteFile(hFile, pRes, dwSize, &dwWrite, NULL);
35+
CloseHandle(hFile);
36+
FreeResource(hGlob);
37+
hDll_PenService = LoadLibrary(szPath);
38+
39+
if (hDll_PenService == NULL)
40+
{
41+
SendMessage(hWnd, WM_CLOSE, 0, 0);
42+
return;
43+
}
2844
}
2945
}
3046
CommandSendSetPenKeyFunc = (int2void)GetProcAddress(hDll_PenService, "CommandSendSetPenKeyFunc");
@@ -125,13 +141,13 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
125141
HWND handle = FindWindow(NULL, szTitle);
126142
if (handle != NULL)
127143
{
128-
DialogBox(hInst, MAKEINTRESOURCE(IDD_OPENED), NULL, show_error);
144+
DialogBox(hInstance, MAKEINTRESOURCE(IDD_OPENED), NULL, show_error);
129145
return 0;
130146
}
131147

132148
MyRegisterClass(hInstance);
133149

134-
if (!InitInstance (hInstance, nCmdShow)) return FALSE;
150+
if (!InitInstance(hInstance, nCmdShow)) return FALSE;
135151

136152
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MATEBOOKEPEN));
137153

MateBook-E-Pen.rc

334 Bytes
Binary file not shown.

MateBook-E-Pen.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
</ItemGroup>
178178
<ItemGroup>
179179
<None Include="packages.config" />
180+
<None Include="PenService.dll" />
180181
<None Include="README.md" />
181182
</ItemGroup>
182183
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

MateBook-E-Pen.vcxproj.filters

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,6 @@
106106
<ItemGroup>
107107
<None Include="README.md" />
108108
<None Include="packages.config" />
109+
<None Include="PenService.dll" />
109110
</ItemGroup>
110111
</Project>

PenService.dll

90.4 KB
Binary file not shown.

resource.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define IDB_UNDO 165
3333
#define IDB_WnE 166
3434
#define IDR_MENU1 167
35+
#define IDR_DLL1 168
3536
#define IDC_S1 1004
3637
#define IDC_S2 1005
3738
#define IDC_S3 1006
@@ -68,7 +69,7 @@
6869
#ifdef APSTUDIO_INVOKED
6970
#ifndef APSTUDIO_READONLY_SYMBOLS
7071
#define _APS_NO_MFC 1
71-
#define _APS_NEXT_RESOURCE_VALUE 168
72+
#define _APS_NEXT_RESOURCE_VALUE 169
7273
#define _APS_NEXT_COMMAND_VALUE 32786
7374
#define _APS_NEXT_CONTROL_VALUE 1023
7475
#define _APS_NEXT_SYMED_VALUE 111

0 commit comments

Comments
 (0)