Python: dostęp do funkcji DLL przy użyciu ctypes - dostęp przez funkcję * nazwa * kończy się niepowodzeniem
myPythonClient
(poniżej) chce wywołać aringBell
funkcja (ładowana z biblioteki DLL za pomocąctypes
). Jednak próba uzyskania dostępuringBell
przez jegoimię skutkujeAttributeError
. Czemu?
RingBell.h
zawiera
namespace MyNamespace
{
class MyClass
{
public:
static __declspec(dllexport) int ringBell ( void ) ;
} ;
}
RingBell.cpp
zawiera
#include <iostream>
#include "RingBell.h"
namespace MyNamespace
{
int __cdecl MyClass::ringBell ( void )
{
std::cout << "\a" ;
return 0 ;
}
}
myPythonClient.py
zawiera
from ctypes import *
cdll.RingBell[1]() # this invocation works fine
cdll.RingBell.ringBell() # however, this invocation errors out
# AttributeError: function 'ringBell' not found