Tools: VS2010 python2.7 (if you are using Python with 64-bit, the generated DLL also uses x64)
System: Win7pro 64bit
first, the creation of DLL projects and the generation of DLL files:
New Project-->win32 Project-->next-->dll,empty Project-->finish
If you do not select Empty project, several files are created automatically. Where Dllmain.cpp is the entry point for the DLL application.
Add head files (mydll.h), add source files (mydll.cpp)
In the header file:
#ifndef Lib_h
#define Lib_h
extern "C" {_declspec (dllexport) int Add (int* x, int y);
#endif
In the Mydll.cpp:
#include "mydll.h"
int Add (int* x, int y)
{
int a = (*x);
a++;
(*x) = A;
return y;
}
Ctrl+f7 after compiling no problem, on Build-->build Mydll, generated mydll.lib and MyDLL.DLL.
/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
Tips
(
Debug: Debug version, contains debugging information, does not do any optimization, easy programmer to debug the program.
Release: Released version, in the amount of code and running speed are optimized to make the program run faster, easy to use users. )
/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
Python calls to functions inside a DLL.
For an int with a intx pointer type, you want to handle the parameters in:
Import cTYPES
Dlltest = ctypes.cdll.LoadLibrary (' Dlltest.dll ')
A = Ctypes.c_int (5)
Print Dlltest.add (Ctypes.byref (a), 4)
Print A.value