-
C dll for vB
I want to recode an algorithm in my vb-program in c/c++ for faster execution. I think a dll is the only way to do that. But I have many problems using the vB "Declare" directive, so my quesiton is: is there an easy way to link into vBs COM? Is there maybe a predefined skeleton that provides functions to vB where I can simply write my function and register it?
This is something urgent, so plz help quick!
CornedBee
-
You don't need to register non-COM DLLs. Just code the function in C, and write a Declare for it.
If you search this forum for "Declare" (use my username) I made a long post about it.
-
i can't find the post, maybe you can supply a link?
or tell me exactly what i have to type in the search form
thx
CornedBee
-
Ok, now i have a basic dll (like your testdll) up and running.
Now on to the real problem: why can't I change an argument passed with ByRef, like in this sample:
C:
PHP Code:
void STDCALL reffunc(long* pArg)
{
// output *pArg, correct value
*pArg = 100;
// output *pArg, correct value
}
vB:
Code:
declare sub reffunc lib LIBNAME (ByRef arg as Long)
private sub command1_click()
dim i as long
i = 20
reffunc (i)
// output i, still 20 :(
:mad: :mad: :mad: :mad: :mad:
I have no idea why this happens, it seems that the ByRef call still allocates a copy of the parameter :(:( :(
CornedBee
-
How about trying something like this:
Code:
declare sub reffunc lib LIBNAME (ByVal pArg as Long)
' ...
dim i as long
i = 20
reffunc VarPtr(i)
'...
This time, it's passing a Long value directly, using the return value of VarPtr which is like C's & operator: VarPtr(i) = &i
-
:cool: :cool: Thanks alot!:cool: :cool:
This works, and it even works with arrays!
:) :) You da man!!!!:D :D
Or, like those at the js-forum would put it:
:confused: -> :eek: -> :cool:
(/me builds a shrine for parksie)
:) :) :) :) :) :) :)
-
Hehe thanks :) Always nice to be appreciated ;)
Actually, whenever pointers are needed I always pass a Long by value (ByVal) using VarPtr (I'm still undecided on whether StrPtr does much different).