vc写dll vb au3 call 注意用dumpbin 查看dll内实际函数名
#include <windows.h>
#include <stdlib.h>
#include <string.h>
_declspec(dllexport) void __stdcall sort(char *str[], int size, int linesize);
#include "vcdll.h"
int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
return TRUE;
}
int mycompare (const void * a, const void * b)
{
return strcmp((char *)a, (char *)b);
}
_declspec(dllexport) void __stdcall sort(char *str[], int size, int linesize)
{
qsort(str, size, linesize, mycompare);
MessageBox(NULL, "DllCallSortFinsh","", MB_OK);
}
#Include <Array.au3>
Dim $str_arr[5]=["我的","a de","啊的","zh","什么"]
Dim $str_st
Dim $i
Dim $array_size
$str_st = ""
$array_size = UBound($str_arr)
For $i = 1 To $array_size
$str_st &= "char s" & $i & "[256];"
Next
#cs
C 定义结构体变量st
struct {
char s1[256];
char s2[256];
char s3[256];
char s4[256];
char s5[256];
}st;
#ce
Dim $st = DllStructCreate($str_st)
Dim $asc_arr
Dim $j
For $i = 1 To $array_size
$asc_arr = StringToASCIIArray($str_arr[$i-1], 0, StringLen($str_arr[$i-1]), 1)
For $j = 0 To UBound($asc_arr)-1
DllStructSetData($st, "s" & $i,$asc_arr[$j], $j+1)
Next
DllStructSetData($st, "s" & $i, Chr(0), $j+1)
Next
ConsoleWrite("排序前:" & @CRLF)
For $i = 1 To $array_size
$str_arr[$i-1] = DllStructGetData($st, "s" & $i)
ConsoleWrite( $str_arr[$i-1] & @CRLF)
Next
_ArrayDisplay($str_arr, "排序前")
DllCall("vcdll.dll", "none", "_sort@12", "long", DllStructGetPtr($st), "long", $array_size, "long",256)
ConsoleWrite(">>>排序后:" & @CRLF)
For $i = 1 To $array_size
$str_arr[$i-1] = DllStructGetData($st, "s" & $i)
ConsoleWrite( $str_arr[$i-1] & @CRLF)
Next
_ArrayDisplay($str_arr, "排序后")
|