目前有一个DLL函数,是用DELPHI来实现的,现在我要用VC来动态调用,但是怎么调用都不对,请各位高手帮忙。
function SendString(Addr: byte; Str: string; FontName: string; ntSize: integer; FontColor, FontStyle,FontAglin: byte; dWidth, dHeight, rWidth,rHeight, pLeft, pTop: integer; EntMode, EntSpeed, Delay: integer):Integer;
我的申明:
typedef int (WINAPI *Type_SendString)(unsigned char ,char *,char *,
int ,unsigned char ,unsigned char , unsigned char ,
int , int ,int ,int ,int ,int ,int ,int ,int );Type_SendString Proc_SendString;
Proc_SendString =(Type_SendString)GetProcAddress(hModule, "SendString");
调用:Proc_SendString(addr,FontName,FontName,FontSize,
FontColor,FontStyle,FontAglin,dWidth,dHeight,rWidth,rHeight,pLeft,pTop,EntMode,EntSpeed,Delay);
报错:
Unhandled exception in DllTest.exe (LM_DLL_RT.DLL): 0xC0000005: Access Violation.
function SendString(Addr: byte; Str: string; FontName: string; ntSize: integer; FontColor, FontStyle,FontAglin: byte; dWidth, dHeight, rWidth,rHeight, pLeft, pTop: integer; EntMode, EntSpeed, Delay: integer):Integer;
我的申明:
typedef int (WINAPI *Type_SendString)(unsigned char ,char *,char *,
int ,unsigned char ,unsigned char , unsigned char ,
int , int ,int ,int ,int ,int ,int ,int ,int );Type_SendString Proc_SendString;
Proc_SendString =(Type_SendString)GetProcAddress(hModule, "SendString");
调用:Proc_SendString(addr,FontName,FontName,FontSize,
FontColor,FontStyle,FontAglin,dWidth,dHeight,rWidth,rHeight,pLeft,pTop,EntMode,EntSpeed,Delay);
报错:
Unhandled exception in DllTest.exe (LM_DLL_RT.DLL): 0xC0000005: Access Violation.
函数调用成功了
typedef int (__stdcall *Type_InitLed)(int Width,int Height,int DColor);
function StrLCopy(Dest: PChar; const Source: PChar; MaxLen: Cardinal): PChar; assembler;
asm
PUSH EDI
PUSH ESI
PUSH EBX
MOV ESI,EAX
MOV EDI,EDX
MOV EBX,ECX
XOR AL,AL
TEST ECX,ECX
JZ @@1
REPNE SCASB
JNE @@1
INC ECX
@@1: SUB EBX,ECX
MOV EDI,ESI
MOV ESI,EDX
MOV EDX,EDI
MOV ECX,EBX
SHR ECX,2
REP MOVSD
MOV ECX,EBX
AND ECX,3
REP MOVSB
STOSB
MOV EAX,EDX
POP EBX
POP ESI
POP EDI
end;function StrPCopy(Dest: PChar; const Source: string): PChar;
begin
Result := StrLCopy(Dest, PChar(Source), Length(Source));
end; 有条件还是让Delphi的dll字符串参数改为PChar;别说被C语言调用了,就算dephi调用含有string参数的dll函数都要引用ShareMem单元,总之dll函数最好不要含有string类型的参数