繁体   English   中英

如何在 python 中加载 C#/C++ dll?

[英]How to load a C#/C++ dll in python?

Now I have only a DLL file which writen in C# and C++ mixed(C# code call the C++ natvie code inside) I know, I want to wrap this DLL file with Python(ctypes), using a refoctor(dnSpy) to reverse the DLL我找到了名为 s_set_server_public_key 的 function。

所以我的问题是如何使用 Python 来调用这个 function? 附上DLL,你能给我一些建议吗? 非常感谢!!! 在此处输入图像描述

我认为这个答案对你有用:

import ctypes

# Load DLL into memory.

hllDll = ctypes.WinDLL ("c:\\PComm\\ehlapi32.dll")

# Set up prototype and parameters for the desired function call.
# HLLAPI

hllApiProto = ctypes.WINFUNCTYPE (
    ctypes.c_int,      # Return type.
    ctypes.c_void_p,   # Parameters 1 ...
    ctypes.c_void_p,
    ctypes.c_void_p,
    ctypes.c_void_p)   # ... thru 4.
hllApiParams = (1, "p1", 0), (1, "p2", 0), (1, "p3",0), (1, "p4",0),

# Actually map the call ("HLLAPI(...)") to a Python name.

hllApi = hllApiProto (("HLLAPI", hllDll), hllApiParams)

# This is how you can actually call the DLL function.
# Set up the variables and call the Python name with them.

p1 = ctypes.c_int (1)
p2 = ctypes.c_char_p (sessionVar)
p3 = ctypes.c_int (1)
p4 = ctypes.c_int (0)
hllApi (ctypes.byref (p1), p2, ctypes.byref (p3), ctypes.byref (p4))

如何使用 Python 中的 DLL 文件?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM