1. The exported function of VC + + DLL is defined as the export function of standard C:
Copy Code code as follows:
#ifdef Lrdlltest_exports
#define LRDLLTEST_API __declspec (dllexport)
#else
#define LRDLLTEST_API __declspec (dllimport)
#endif
extern "C" Lrdlltest_api int Sum (int a, int b);
extern "C" Lrdlltest_api void GetString (char* pchar);
A + b
LRDLLTEST_API int Sum (int a, int b)
{
return a + B;
}
Get a string
Lrdlltest_api void GetString (char* pchar)
{
strcpy (Pchar, "Hello DLL");
}
2. The python call is as follows:
Copy Code code as follows:
From ctypes Import *
Filename= "LRDllTest.dll"
Func=cdll. LoadLibrary (FileName)
str = Create_string_buffer (20)
n = func. Sum (2, 3)
Func. GetString (str)
Print n
Print Str.raw
Some of the parameter types in the C language are as detailed as: http://www.python.org/doc/2.5/lib/node454.html
3. Output Result:
5
Hello DLL