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