python调用dll

 

 

回家试

python 控制wlan连接

 

---------------------------------

10

hui调 是__stdcall的这种,改成这样既可

callback_type1 = WINFUNCTYPE(c_void_p,c_uint)

 

9

python 控制连接wifi

https://blog.csdn.net/Mmagic1/article/details/120066894

 

 

8待解决

 python调动态库遗留问题,to thi

// dllmain.cpp : 定义 DLL 应用程序的入口点。
#include "stdafx.h"

#define DLLEXPORT extern "C" __declspec(dllexport) //放在 #include "stdafx.h" 之后
//两数相加
DLLEXPORT int __stdcall sum(int a, int b) {
    return a + b;
}


DLLEXPORT int __stdcall testchap(int a, char* strP) {

    strcpy_s(strP,6,"hello");
    return 1;
}


DLLEXPORT int __stdcall testchapp(int a, char** strPp) {

    strcpy_s(*strPp, 6, "hello");
    return 1;
}

#define DLL_CAL_BACK __stdcall
typedef void (DLL_CAL_BACK *FUNCTION)(unsigned channel, unsigned char * item, unsigned char * msgType, unsigned char * key, unsigned char * desc);

//typedef void(DLL_CAL_BACK *FUNCTION1)(unsigned int channel, unsigned char * item);

typedef void(__stdcall *FUNCTION1)(unsigned int channel);
DLLEXPORT void __stdcall testCalBack(FUNCTION1 callBack) {
    callBack(1);
    //callBack(1, (unsigned char *)"ok");
}

 

 

from ctypes import *

#----------以下四种加载DLL方式皆可—————————
#pDll = WinDLL("./pyDll.dll")
pDll = windll.LoadLibrary("./pyDll.dll")

#pDll = cdll.LoadLibrary("./pyDll.dll")
res = pDll.sum(1,2)
#打印返回结果
print(res)
print('--------------')



callback_type1 = CFUNCTYPE(c_void_p,c_uint)

def callback_func1(p1):
    print(p1)
    return 1

callable_ptr1 = callback_type1(callback_func1)


res = pDll.testCalBack(callable_ptr1)

 

 

 

 

 

 

 

 

 

 

 

7、这个错误不是stdcall原因??

https://bbs.csdn.net/topics/392155464

 

 

__stdcall 回调函数

 C++与Python跨语言调用DLL实操-CSDN博客

 

6.回调函数

 

typedef int ( *FUNCTION1)(unsigned channel, unsigned char * item);


DLLEXPORT void testCalBack(FUNCTION1 callBack) {
   
    callBack(1, (unsigned char *)"ok");
}
callback_type1 = CFUNCTYPE(c_int,c_uint,c_char_p)

def callback_func1(p1,p2):
    print(p1,p2)
    return 1

callable_ptr1 = callback_type1(callback_func1)


res = pDll.testCalBack(callable_ptr1)

两个问题 1是回调函数是void的处理  

改成这样

callback_type1 = CFUNCTYPE(c_void_p,c_uint,c_char_p)

 

2、带   __stdcall 的

 

 

 

 

 

 

 

5、更合理方案

from ctypes import *

#----------以下四种加载DLL方式皆可—————————
# pDLL = WinDLL("./myTest.dll")
# pDll = windll.LoadLibrary("./myTest.dll")

pDll = cdll.LoadLibrary("./pyDll.dll")
c_char_datas = (c_char_p * 1)()
c_chara = (c_char* 512)()
#c_chara.value = bytes('11',encoding='utf-8')
c_char_datas[0] = c_char_p(c_chara.value)
res = pDll.testchapp(1,c_char_datas)
print(*c_char_datas)

 

 

4、

第一个成功的char**

from ctypes import *

#----------以下四种加载DLL方式皆可—————————
# pDLL = WinDLL("./myTest.dll")
# pDll = windll.LoadLibrary("./myTest.dll")

pDll = cdll.LoadLibrary("./pyDll.dll")
res = pDll.sum(1,2)
#打印返回结果
print(res)




file_num = 5

c_char_datas = (c_char_p * file_num)()
for j in range(file_num):
    c_chara = (c_char* 6)()
    c_chara.value = bytes('11',encoding='utf-8')
    c_char_datas[j] = c_char_p(c_chara.value)

res = pDll.testchapp(1,c_char_datas)

#print(c_char_datas)
print(*c_char_datas)

 

#include "stdafx.h"

#define DLLEXPORT extern "C" __declspec(dllexport) //放在 #include "stdafx.h" 之后
//两数相加
DLLEXPORT int sum(int a, int b) {
    return a + b;
}


DLLEXPORT int testchap(int a, char* strP) {

    strcpy_s(strP,6,"hello");
    return 1;
}


DLLEXPORT int testchapp(int a, char** strPp) {

    strcpy_s(*strPp, 6, "hello");
    return 1;
}

 

 

 

1、

https://blog.csdn.net/qq_37377257/article/details/122966999

 

 

sn = (c_char* 64)()
res = pDll.InitDllParam(2,2,str,sn)
print(*sn)

 

2、指针的指针就看

https://blog.csdn.net/Olivia_CFS/article/details/126692764

 

 

 

pSn = (c_char_p * 1)()
 
 
 
https://blog.csdn.net/f120854632/article/details/90241104
posted @ 2025-04-25 16:03  cnchengv  阅读(11)  评论(0)    收藏  举报