在Python中使用out参数从IDL文件调用函数

时间:2018-12-10 16:18:44

标签: python server com idl tlb

我正在尝试从IDL文件中调用某些函数。 这是我的IDL文件:

// This file will be processed by the MIDL tool to
// produce the type library (File.tlb) and marshalling code.

import "oaidl.idl";
import "ocidl.idl";

[
    object,
    uuid(43EA61FC-C17E-429B-8AAD-B71CC2F53098),
    dual,
    nonextensible,
    helpstring("IFile_RemoteInterface Interface"),
    pointer_default(unique)
]
interface IFile_RemoteInterface : IDispatch{
    [id(5), helpstring("method GetState")]         HRESULT GetState(BSTR sequencename, [out] LONG* sequencestate);  
};
[
    uuid(1F19FE19-8626-4ADC-9787-077CD9D06563),
    version(2.0),
    helpstring("File Remote Interface 2.0")
]
library FileLib
{
    importlib("stdole2.tlb");
    [
        uuid(E0FDA055-B882-4026-A3D9-2EC863FCDFB9),
        helpstring("File_RemoteInterface Class")
    ]
    coclass File_RemoteInterface
    {
        [default] interface IFile_RemoteInterface;
    };
};

我已经使用MIDL Compiler从其中生成了一个TLB文件,并且已经使用“ python fileBelow.py / regserver”注册了COM服务器(如果我错了,请更正我,我是Python编程的新手) :

import comtypes
import comtypes.server.localserver

from comtypes.client import GetModule
# generate wrapper code for the type library, this needs
# to be done only once (but also each time the IDL file changes)
GetModule("File.tlb")

from comtypes.gen.FileLib import File_RemoteInterface

class FileImpl(File_RemoteInterface):
    # registry entries
    _reg_threading_ = "Both"
    _reg_progid_ = "File.Object.1"
    _reg_novers_progid_ = "File.Object"
    _reg_desc_ = "Python engine for File"
    _reg_clsctx_ = comtypes.CLSCTX_INPROC_SERVER | comtypes.CLSCTX_LOCAL_SERVER
    _regcls_ = comtypes.server.localserver.REGCLS_MULTIPLEUSE


    def GetState(self,a,b):
        return a      // i don't know what exactly should i write here


if __name__ == "__main__":
    from comtypes.server.register import UseCommandLine
    UseCommandLine(FileImpl)

我正在尝试调用GetState方法:

from comtypes.client import CreateObject
from ctypes import *


cale = "some_path"

x = CreateObject("File.Object")

x.GetState(cale,b)

但是我仍然遇到相同的错误:TypeError:调用正好接受2个参数(给定3个)。我读到有关此错误的信息,其中包含self参数,但我已在def中添加了该参数。

如果您有任何想法,请告诉我!

0 个答案:

没有答案