-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
89 lines (86 loc) · 2.18 KB
/
main.cpp
File metadata and controls
89 lines (86 loc) · 2.18 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
78
79
80
81
82
83
84
85
86
87
88
89
#include <Python.h>
#include <Windows.h>
#include "spider.h"
extern "C"
{
__declspec(dllexport) void __stdcall _spider(char *ip,struct Signal *signal)
{
return spider(ip,signal);
}
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
static wchar_t* program;
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
program = Py_DecodeLocale("spider", NULL);
//dll��ʼ����ʱ����ã�����python3��д����python2�ijɣ�initrun()���μ����ɵ�run.h
PyImport_AppendInittab("spider", PyInit_spider);
Py_SetProgramName(program);
Py_Initialize();
PyImport_ImportModule("spider");
break;
case DLL_PROCESS_DETACH:
PyMem_RawFree(program);
Py_Finalize();
break;
}
return TRUE;
}
//int main(int argc, char* argv[])
//{
// PyObject* pmodule;
// wchar_t* program = NULL;
//
// //program = Py_DecodeLocale(argv[0], NULL);
// /*if (program == NULL) {
// fprintf(stderr, "Fatal error: cannot decode argv[0], got %d arguments\n", argc);
// exit(1);
// }*/
//
// /* Add a built-in module, before Py_Initialize */
// if (PyImport_AppendInittab("embedded", PyInit_demo) == -1) {
// fprintf(stderr, "Error: could not extend in-built modules table\n");
// exit(1);
// }
//
// /* Pass argv[0] to the Python interpreter */
// //Py_SetProgramName(program);
//
// /* Initialize the Python interpreter. Required.
// If this step fails, it will be a fatal error. */
// Py_Initialize();
//
// /* Optionally import the module; alternatively,
// import can be deferred until the embedded script
// imports it. */
// /*pmodule = PyImport_ImportModule("embedded");
// if (!pmodule) {
// PyErr_Print();
// fprintf(stderr, "Error: could not import module 'embedded'\n");
// goto exit_with_error;
// }*/
//
// /* Now call into your module code. */
// if (spider() < 0) {
// PyErr_Print();
// fprintf(stderr, "Error in Python code, exception was printed.\n");
// goto exit_with_error;
// }
//
// /* ... */
//
// /* Clean up after using CPython. */
// PyMem_RawFree(program);
// Py_Finalize();
//
// return 0;
//
// /* Clean up in the error cases above. */
// exit_with_error:
// PyMem_RawFree(program);
// Py_Finalize();
// return 1;
//}
//