-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (71 loc) · 2.38 KB
/
main.cpp
File metadata and controls
77 lines (71 loc) · 2.38 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
73
74
75
76
77
#include <iostream>
#include <windows.h>
// part that normally should be in resource.h file
#define IDR_RCDATA1 300
#define IDS_STRING1 1
#define IDS_STRING2 2
#define IDS_STRING3 3
// end of this part
// dynamic procedure type definition
typedef unsigned long (CALLBACK *FPROC)(unsigned char*);
// dynamic procedure definition
FPROC DLL_1;
unsigned char CALLBACK __export Test(unsigned char* test) {
return ((unsigned char)DLL_1(test));
};
// end of dynamic procedure definition
int main(void) {
unsigned char test[5];
char test3[256];
HINSTANCE hLib=LoadLibrary("testlib2.dll");
if(hLib < 32) {
std::cout << "FAIL" << std::endl;
} else {
std::cout << "OK" << std::endl;
DLL_1=(FPROC)GetProcAddress(hLib,"Test");
if(DLL_1!=NULL) {
std::cout << "OK" << std::endl;
test[0]=3;
test[1]=4;
std::cout << (unsigned int)Test(test) << std::endl;
}
HGLOBAL hMem = LoadResource(hLib,FindResource(hLib,MAKEINTRESOURCE(IDR_RCDATA1),RT_RCDATA));
if(hMem==NULL) {
std::cout << "FAIL" << std::endl;
} else {
std::cout << "OK" << std::endl;
WORD *test2 = (WORD*)LockResource(hMem);
if(test2==NULL) {
std::cout << "FAIL" << std::endl;
} else {
std::cout << "OK" << std::endl;
unsigned int x=0;
while(test2[x]) {
test3[x]=(char)test2[x];
++x;
}
test3[x]=0;
std::cout << test3 << std::endl;
UnlockResource(hMem);
}
FreeResource(hMem);
}
if(LoadString(hLib,IDS_STRING1,test3,256)) {
std::cout << test3 << std::endl;
} else {
std::cout << "FAIL" << std::endl;
}
if(LoadString(hLib,IDS_STRING2,test3,256)) {
std::cout << test3 << std::endl;
} else {
std::cout << "FAIL" << std::endl;
}
if(LoadString(hLib,IDS_STRING3,test3,256)) {
std::cout << test3 << std::endl;
} else {
std::cout << "FAIL" << std::endl;
}
FreeLibrary(hLib);
}
return 0;
}