我想从一个软件SDK中提供一个DLL文件并创建一个python包装,以便将其与我的其他代码库相集成。我在网上关注了很多指南,仍然没有运气。如何为一个DLL库创建一个Python包装
目前的Python代码我是:
from ctypes import *
from ctypes.wintypes import HWND
import os
class OptistarDLL(object):
dll_path = 'OSDS142MRT.dll'
with open(dll_path) as thefile:
pass
_dll = WinDLL(dll_path)
init_library = _dll['OSDS142M_Initialize']
init_library.restype = c_int
init_library.argtypes = (c_int, c_bool, HWND, c_bool, c_int)
class OpticstarControl(object):
def __init__(self):
err = OptistarDLL.init_library(c_int(0), c_bool(False), HWND(0), c_bool(False), c_int(0))
if err != 0:
raise Exception("Doom")
我使用的SDK文档提供了以此为函数的头:
DLLDIR int OSDS142M_Initialize(int iModel, bool bOutVid, HWND hwOutVid, bool bStarView, int iRt);
而且例如PDF给出:
OSDS142M_Initialize(1, false, 0, true, 0);
初始化目前仅让我知道
ValueError: Procedure probably called with too many arguments (20 bytes in excess)
我看了,但不被理解,关于WinDLL
VS CDLL
,当我改变CDLL
DLL的加载失败。我也在所有的指南中看到,其中的标题有DLLEXPORT
,我的DLLDIR
,我不知道这是否是一个问题。
有没有人有任何想法?
嗨大卫,当试图通过'CDLL'调用时,我得到一个返回码13.然而,它看起来实例化没有像在WinDLL一样失败,在某种意义上该方法实际上是被调用的。因此,我认为这可能是一个图书馆问题,所以我会用Opticstar来解决这个问题。 – Samreay 2014-10-18 03:23:56
是的。返回代码的13个声音,如你的interop现在是正确的。 – 2014-10-18 07:34:17