Python: acessando a função DLL usando ctypes - o acesso por função * name * falha
myPythonClient
(abaixo) quer invocar umringBell
função (carregada de uma DLL usandoctypes
). No entanto, tentando acessarringBell
através do seunome resulta em umAttributeError
. Por quê?
RingBell.h
contém
namespace MyNamespace
{
class MyClass
{
public:
static __declspec(dllexport) int ringBell ( void ) ;
} ;
}
RingBell.cpp
contém
#include <iostream>
#include "RingBell.h"
namespace MyNamespace
{
int __cdecl MyClass::ringBell ( void )
{
std::cout << "\a" ;
return 0 ;
}
}
myPythonClient.py
contém
from ctypes import *
cdll.RingBell[1]() # this invocation works fine
cdll.RingBell.ringBell() # however, this invocation errors out
# AttributeError: function 'ringBell' not found