0

ctypesを使用して、digi Advanced Device DiscoveryプロトコルライブラリをPythonで使用しようとしています。コンテキスト: Windows 7 x64 python 2.7.5 dll ライブラリ

ここに私の現在のコードがあります:

guid = (0xbf6db409,0xc83d,0x44a3,0xa3,0x6d,0x21,0x79,0x7d,0x2f,0x73,0xf9)

class ADDP():
    from ctypes import Structure
    class GUID(Structure):
        from ctypes.wintypes import DWORD,WORD,BYTE
        _fields_ = [("Data1",DWORD),
                    ("Data2",WORD),
                    ("Data3",WORD),
                    ("Data4",BYTE * 8)]
    def __init__(self, guid): 
        from ctypes import windll, c_void_p, c_byte, pointer,c_char,POINTER
        from ctypes.wintypes import HANDLE
        import ctypes
        self.dll = windll.LoadLibrary("D:\\Lib\\addp.dll")
        self.guid = self.GUID()
        self.guid.Data1 = guid[0]
        self.guid.Data2 = guid[1]
        self.guid.Data3 = guid[2]
        self.guid.Data4 = (c_byte * 8)(guid[3],guid[4],guid[5],guid[6],guid[7],guid[8],guid[9],guid[10])
        addpopen = self.dll[1]
        addpopen.argtypes = [POINTER(self.GUID),]
        addpopen.restype = c_void_p
        #print addpopen.restype
        self.handler = addpopen(pointer(self.guid))
        if self.handler == None:
            raise RuntimeError()
            self.opened = False
        else:
            self.opened = True
    def isOpen(self):
        return self.opened

    def Discover(self):
        from ctypes import c_int
        srch = self.dll[6]
        srch.restype = c_int
        print srch(self.handler,10,10)

    def Close(self):
        close = self.dll[3]
        close.restype = None
        self.opened = False
        #print close(self.handler)


conn = ADDP(guid)
#print conn.handler
conn.Discover()
#conn.Close()
print conn.handler

ac関数から返されたハンドルを処理する方法をたくさん検索しましたが、それについて多くを見つけることができませんでした.ctypesのドキュメントをしばらく読み、ヘッダーファイルも調べました..

ハンドルはヘッダーファイルで定義されています

typedef void* addp_handle_t;

そのため、「restype」を「c_void_p」に設定する必要があると想定しました。関数は、ヘッダー ファイルで指定された「None」を常に返し、エラーが発生した場合は「None」を返します。それ以外の場合は、ADDP セッションへのハンドルを返します。

もう1つ、このdllは名前で関数をエクスポートしません...多かれ少なかれ、引数の予想されるバイトによってどの関数が何であるかを推測する必要がありました。

これに関するアイデアはありますか?Googleコードでプロジェクトを見つけましたが、どうやらうまくいかなかったようです...他の詳細が必要な場合は、

4

0 に答える 0