myPythonClient
(下面)希望调用ringBell
函数(使用ctypes
从DLL加载)。然而,试图通过其名称访问ringBell
会导致AttributeError
。为什么?
RingBell.h
包含
namespace MyNamespace
{
class MyClass
{
public:
static __declspec(dllexport) int ringBell ( void ) ;
} ;
}
RingBell.cpp
包含
#include <iostream>
#include "RingBell.h"
namespace MyNamespace
{
int __cdecl MyClass::ringBell ( void )
{
std::cout << "\a" ;
return 0 ;
}
}
myPythonClient.py
包含
from ctypes import *
cdll.RingBell[1]() # this invocation works fine
cdll.RingBell.ringBell() # however, this invocation errors out
# AttributeError: function 'ringBell' not found
可能是因为C++名称被编译器损坏,而不是从DLL导出为^ {CD1>}。您检查过它在导出的名称中是否与此完全相同吗?
现在一切正常:)总结你的文章:
用C++编写DLL:然后可以使用program link.exe查看dll中的实际函数名。 link.exe在MSVC2010中的示例如下:
使用:
你看到的是:
然后在python中,您可以将其导入为:
相关问题 更多 >
编程相关推荐