小编And*_*nko的帖子

Segfault调用标准windows .dll从python ctypes与wine

我正试图在我在Linux上运行的Python脚本中调用Kernel32.dll中的某些函数.正如JohannesWeiß所指出的如何在Linux上从python调用Wine dll?我正在通过ctypes.cdll.LoadLibrary()加载kernel32.dll.so库并且加载正常.我可以看到kernel32加载,甚至里面有GetLastError()函数.但是每当我试图调用该函数时,我都会遇到段错误.

import ctypes

kernel32 = ctypes.cdll.LoadLibrary('/usr/lib/i386-linux-gnu/wine/kernel32.dll.so')

print kernel32
# <CDLL '/usr/lib/i386-linux-gnu/wine/kernel32.dll.so', handle 8843c10 at b7412e8c>

print kernel32.GetLastError
# <_FuncPtr object at 0xb740b094>

gle = kernel32.GetLastError
# OK

gle_result = gle()
# fails with
# Segmentation fault (core dumped)

print gle_result
Run Code Online (Sandbox Code Playgroud)

首先,我在考虑调用约定差异,但毕竟它似乎没问题.我结束了测试简单函数GetLastError函数没有任何参数,但我仍然得到Segmentation故障.

我的测试系统是Ubuntu 12.10,Python 2.7.3和wine-1.4.1(一切都是32位)

UPD

我继续我的测试,并找到几个我可以通过ctypes调用而没有segfault的函数.例如,我可以命名Beep()和GetCurrentThread()函数,许多其他函数仍然给我segfault.我创建了一个小的C应用程序来测试没有python的kernel32.dll.so库,但我得到了基本相同的结果.

int main(int argc, char **argv) 
{

   void *lib_handle;

   #define LOAD_LIBRARY_AS_DATAFILE            0x00000002

   long (*GetCurrentThread)(void);
   long (*beep)(long,long);
   void (*sleep)(long);   
   long (*LoadLibraryExA)(char*, long, long);


   long x;
   char *error; …
Run Code Online (Sandbox Code Playgroud)

python linux ctypes wine segmentation-fault

6
推荐指数
1
解决办法
2797
查看次数

标签 统计

ctypes ×1

linux ×1

python ×1

segmentation-fault ×1

wine ×1