我的任务是将ac包"包装"到python类中.在这个问题上,文档非常模糊.似乎他们期望只有高级python用户才能实现ctypes.好吧,我是python的初学者,需要帮助.
一步一步的帮助将是美好的.
所以我有我的c库.我该怎么办?我把哪些文件放在哪里?如何导入库?我读到可能有一种方法可以"自动换行"到Python?
(顺便说一句,我在python.net上做了ctypes教程,但它不起作用.意思是我认为他们假设我应该能够完成剩下的步骤.
实际上这是我用他们的代码得到的错误:
File "importtest.py", line 1
>>> from ctypes import *
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
我真的可以一步一步地帮助这个!谢谢〜
myPythonClient(下面)想要调用一个ringBell函数(使用DLL加载ctypes).但是,尝试ringBell通过其名称访问会导致AttributeError.为什么?
RingBell.h 包含
namespace MyNamespace
{
class MyClass
{
public:
static __declspec(dllexport) int ringBell ( void ) ;
} ;
}
Run Code Online (Sandbox Code Playgroud)
RingBell.cpp 包含
#include <iostream>
#include "RingBell.h"
namespace MyNamespace
{
int __cdecl MyClass::ringBell ( void )
{
std::cout << "\a" ;
return 0 ;
}
}
Run Code Online (Sandbox Code Playgroud)
myPythonClient.py 包含
from ctypes import *
cdll.RingBell[1]() # this invocation works fine
cdll.RingBell.ringBell() # however, this invocation errors out
# AttributeError: function 'ringBell' …Run Code Online (Sandbox Code Playgroud)