美文网首页
调用动态链接库DLL

调用动态链接库DLL

作者: Bug2Coder | 来源:发表于2019-09-17 16:29 被阅读0次

DLL文件编写

1)__stdcall 调用方式   stdll_sum.cpp

//main.cpp
#define DLLEXPORT extern "C" __declspec(dllexport)

DLLEXPORT int __stdcall sum(int a, int b) {
    return a + b;
}

2)__cdecl 调用方式   cdecl_sum.cpp

//main.cpp
#define DLLEXPORT extern "C" __declspec(dllexport)

DLLEXPORT int __cdecl sum(int a, int b) {
    return a + b;
}

Python调用

lib = ctypes.CDLL('cdecl_sum.dll')
a = lib.sum(1, 2)
print(a)

lib2 = ctypes.WinDLL('stdll_sum.dll') 
a = lib2.summmm(3, 4)
print(a)

相关文章

网友评论

      本文标题:调用动态链接库DLL

      本文链接:https://www.haomeiwen.com/subject/wylcuctx.html