将vba转换为c程序以调用dll函数 [英] convert vba into c program to call a dll function
问题描述
您好,
我有一个调用dll函数的vba脚本。有用。我想转换成C程序。我使用LoadLibrary / GetProcAddress,它们返回非null值,ok。但是当我调用我的新函数时,会出现Windows执行错误。
可能是常规调用问题,或参数格式:我没有任何原型,只有vba脚本调用。
VBA:
选项 explicit
声明 function myfun lib mylib( byval p1 $,p1len as integer , byval p2 $,p2len as integer , byval p3 $,p3len as integer ) as 整数
类型mytype
p1 as string : p1len as integer
p2 as string :p2len as integer
p3 as string :p3len as integer
end 类型
sub main
dim myvar as mytype
dim p1len as integer ,p2len as 整数,p3len as integer
dim p1 $,p2 $,p3 $
让 mytype.p1 = string $( 255 , ):让 mytype.p1len = 255
让 mytype.p2 = string $( 255 , ):让 mytype.p2len = 255
让 mytype.p3 = string $( 255 , ):让 mytype.p3len = 255
ret = myfun(mytype.p1,mytype.p1len,mytype.p2,mytype.p2len,mytype。 p3,mytype.p3l en)
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); // ko here
}
我尝试过另一个大小而不是DWORD,或__stdcall,同样的问题。
请问有什么想法吗?谢谢。
Jean-Claude
,p1len as 整数, byval p2
,p2len as 整数, 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 类型
sub main
dim myvar as mytype
dim p1len as 整数,p2len as integer , p3len as integer
dim P1
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); // ko here
}
I've tried another size than DWORD, or __stdcall, same problem.
Any idea, please ? Thanks.
Jean-Claude
, 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
这篇关于将vba转换为c程序以调用dll函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!