forked from msly/codemanage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path调用sunday.dll.cpp
More file actions
73 lines (54 loc) · 1.67 KB
/
调用sunday.dll.cpp
File metadata and controls
73 lines (54 loc) · 1.67 KB
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
69
70
71
72
//dll 需要一定时间初始化,所以开始启动的时候会有点慢属正常
#include <iostream>
#include <Windows.h>
#include <wininet.h>
#pragma comment(lib, "wininet.lib ")
int main()
{
HINSTANCE hInst = LoadLibraryA("Sunday.dll");
if (!hInst)
{
std::cout<<"无法加载 Sunday.dll!";
getchar();
return 0;
}
std::cout<<"dll 初始化完成!"<<"\n";
std::cout<<"载入字库!(只需要在程序开头载入一次即可)"<<"\n";
typedef int (CALLBACK* LPLoadLib)(char[],char[]);
LPLoadLib LoadLibFromFile = (LPLoadLib)GetProcAddress(hInst, "LoadLibFromFile");
int index = LoadLibFromFile ("12306.lib","123");
if (index == -1)
{
std::cout<<"载入识别库出错。";
getchar();
return 0;
}
std::cout<<"载入识别库完成。"<<"\n";
std::cout<<"下载图片中。。!"<<"\n";
/*
typedef bool (CALLBACK* LPGetCode)(int,char[],char[]);
LPGetCode GetCodeFromFile = (LPGetCode)GetProcAddress(hInst, "GetCodeFromFile");
*/
typedef bool (CALLBACK* LPGetCodeFromBuffer)(int,char*,int,char[]);
LPGetCodeFromBuffer GetCodeFromBuffer = (LPGetCodeFromBuffer)GetProcAddress(hInst, "GetCodeFromBuffer");
char result[16];
HANDLE pfile = CreateFile("6.png",GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
if(pfile == INVALID_HANDLE_VALUE){
std::cout<<"文件打开失败!";
CloseHandle(pfile);
return 0;
}
unsigned long filesize = GetFileSize (pfile, NULL);
char* buffer = new char[filesize];
unsigned long readsize;
ReadFile(pfile,buffer,filesize,&readsize,NULL);
CloseHandle(pfile);
long nCount;
nCount=GetTickCount();
if (GetCodeFromBuffer(index,buffer,filesize,result))
std::cout<<"识别完成 :"<<result<<" ,识别用时: "<<GetTickCount()-nCount;
else
std::cout<<"识别失败!";
getchar();
return 0;
}