-
Notifications
You must be signed in to change notification settings - Fork 19
/
test_dll.cpp
143 lines (132 loc) · 2.76 KB
/
test_dll.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// #include "stdafx.h"
#include "stdio.h"
#include <Windows.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <io.h>
extern "C"
{
class _declspec(dllexport) A
{
public:
A()
{
printf("A construct...\n");
}
const char *whoIsMe()
{
return "Myname is A";
}
~A()
{
printf("A deconstruct...\n");
}
};
_declspec(dllexport) A a;
#define MAX_LINE 3800
#define IMGNUM 20000 //图片所在文件夹中图片的最大数量
char img_files[IMGNUM][1000];
int getFiles(char *path)
{
int num_of_img = 0;
long hFile = 0;
struct _finddata_t fileinfo;
char p[700] = {0};
strcpy(p, path);
strcat(p, "\\*");
if ((hFile = _findfirst(p, &fileinfo)) != -1)
{
do
{
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
continue;
}
else
{
//strcpy(img_files[num_of_img], path);
//strcpy(img_files[num_of_img], "\\");
//strcat(img_files[num_of_img], "\\");
//strcat(img_files[num_of_img++], fileinfo.name);
strcpy(img_files[num_of_img++], fileinfo.name);
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
return num_of_img;
}
_declspec(dllexport) char *search_words(char *aim_code)
{
// char aim_code[20];
//scanf("%s", aim_code);
char root[180];
memset(root, 0x00, sizeof(root));
char xxx[1];
memset(xxx, 0x00, sizeof(xxx));
strcpy(root, "DICT/");
if (aim_code[0] >= 97 && aim_code[0] <= 122)
xxx[0] = aim_code[0] - 32;
root[strlen(root)] = xxx[0];
strcat(root, "/");
//
int num = getFiles(root);
int i, j;
if (1 == num)
{
strcat(root, img_files[0]);
}
else
{
for (i = 0; i < num; ++i)
{
//printf("%s\n", img_files[i]);
for (j = 2; j < 20; j++)
{
if (img_files[i][j] == aim_code[1])
{
strcat(root, img_files[i]);
printf("%s\n", root);
break;
break;
}
}
}
}
/*root[41] = aim_code[0];
strcat(root, "-");
root[43] = aim_code[1];
strcat(root, ".txt");*/
//printf("%s\n", root);
//system("pause");
char buf[MAX_LINE]; /*缓冲区*/
FILE *fp; /*文件指针*/
int len; /*行字符个数*/
int rownum = 0;
if ((fp = fopen(root, "r")) == NULL)
{
printf("cannot read %s", root);
return "cannot translate this words!";
//system("pause");
/*perror("fail to read");
exit(1);*/
}
while (fgets(buf, MAX_LINE, fp) != NULL)
{
len = strlen(buf);
buf[len - 1] = '\0'; /*去掉换行符*/
rownum++;
if (strcmp(buf, aim_code) == 0)
{
fgets(buf, MAX_LINE, fp);
printf("%s %d \n", buf, rownum);
//system("pause");
return buf;
}
}
return "no this words!";
printf("cannot get password!\n");
}
_declspec(dllexport) int g_nUsageCount = 3195;
}