Hello,
I've a vba script calling a dll function. It works. I'd like to convert into C program. I use LoadLibrary/GetProcAddress, they return non null value, ok. But when I call my new function, there is a Windows execution error.
Maybe problem with the convention call, or the parameters format : I don't have any prototype, only the vba script call.
VBA :
option explicit
declare function myfun lib "mylib" (byval p1$, p1len as integer, byval p2$, p2len as integer, byval p3$, p3len as integer) as integer
type mytype
p1 as string : p1len as integer
p2 as string : p2len as integer
p3 as string : p3len as integer
end type
sub main
dim myvar as mytype
dim p1len as integer, p2len as integer, p3len as integer
dim p1$, p2$, p3$
let mytype.p1 = string$(255, " ") : let mytype.p1len = 255
let mytype.p2 = string$(255, " ") : let mytype.p2len = 255
let mytype.p3 = string$(255, " ") : let mytype.p3len = 255
ret = myfun(mytype.p1, mytype.p1len, mytype.p2, mytype.p2len, mytype.p3, mytype.p3len)
end sub
C :
typedef DWORD __cdecl (*GLIX)(char *p1, DWORD p1len, char *p2, DWORD p2len, char *p3, DWORD p3len);
void main(void)
{
HMODULE hm = LoadLibrary(TEXT("C:\\mylib.dll"));
GLIX myfun = (GLIX)GetProcAddress(hm, "myfun");
char *p1, *p2, *p3;
strcpy(p1, " ");
strcpy(p2, " ");
strcpy(p3, " ");
DWORD p1len = 255, p2len = 255, p3len = 255;
myfun(p1, p1len, p2, p2len, p3, p3len); }
I've tried another size than DWORD, or __stdcall, same problem.
Any idea, please ? Thanks.
Jean-Claude