学习了群主的dll教程后,感觉只有写一些测试例程才能理解dll的调用流程
测试环境
autohotkey和c必须都是32位或者64位
c代码
#include <stdlib.h> #include <stdio.h> _declspec(dllexport) int dlltest(int *a,char arr[20]) { FILE *fp; fp = fopen("dlldate.txt","a+"); fprintf(fp,"test\n"); fprintf(fp, "input a: %d\n", *a); fprintf(fp,"input str is %s\n",arr); strcpy(arr,"i have accept\n"); if (NULL == fp) { fclose(fp); } return 10; }
autohotkey代码
va1 := 10 va2 := "autohotkey" va3 := "autohotkey" va4 := "autohotkey" ;第一种调用方法 result := DllCall("C:\source\repos\Dll4\Release\Dll4.dll\dlltest","Int *",va1,"AStr",va2,"Cdecl ") MsgBox,% ErrorLevel if(ErrorLevel != 0) { return } MsgBox,% "va2 Return is" va2 ;返回值会截断,ahk是动态分配内存的,dll处理后,ahk并不知道 VarSetCapacity(va31,100) ;转化为系统码 StrPut(va3,&va31,"CP0") result := DllCall("C:\source\repos\Dll4\Release\Dll4.dll\dlltest","Int *",va1,"Str",va31,"Cdecl ") MsgBox,% ErrorLevel if(ErrorLevel != 0) { return } MsgBox,% "va31 Return is" StrGet(&va31,20,"CP0") VarSetCapacity(va41,100) ;转化为系统码 StrPut(va4,&va41,"CP0") result := DllCall("C:\source\repos\Dll4\Release\Dll4.dll\dlltest","Int *",va1,"Ptr",&va41,"Cdecl ") MsgBox,% ErrorLevel if(ErrorLevel != 0) { return } MsgBox,% "va41 Return is" StrGet(&va41,20,"CP0")
输出结果
test input a: 10 input str is autohotkey test input a: 10 input str is autohotkey test input a: 10 input str is autohotkey
牛逼,你理解的比我深刻
大佬呀