我在 linux ubuntu 中有这个 C++ 代码我想通过 ctype 在 python 中使用这个方法,但不能将参数发送到 ctype.cdl.funcion
C++ 代码:
extern "C" unsigned char* getuserdata(int code,unsigned char* globalkey,unsigned char* key)
{
unsigned char data[256];
KeyA *keya;
keya=new KeyA;
keya->OpenDevice(0);
keya->Init(globalkey,globalkey,globalkey,globalkey);
keya->ReadUserMemory( 0,256,key,data);
return data;
}
示例在 C++ 中使用此函数:
unsigned char g_user[16] = { 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22 };
unsigned char publickey[16] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
printf("function Return: %s\n", getuserdata(0,publickey,g_user));
我的python源代码(不工作!!)是:
from ctypes import *
dl=cdll.LoadLibrary('/home/iman/KCore/kcore/hkey.so');
dl.getuserdata.restype = c_char_p
string_buffers = [addressof(create_string_buffer(16)) ]
string_buffers[0]= "5555555555555555";
string_buffers2 = [addressof(create_string_buffer(16)) ]
string_buffers2[0]="2222222222222222";
st= dl.getuserdata(0,string_buffers,string_buffers2);
print st+"\n";