Python 调用VC++的动态链接库(DLL)

#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");
}

 

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

  

 

posted on 2022-08-03 15:31  帅胡  阅读(64)  评论(0编辑  收藏  举报

导航