Loading two same api dll and declare usage

'Declare Function Todo Lib “test.dll” ( oldProc As Ptr) as ptr
'Declare Function Todo2 Lib “test2.dll” alias “Todo” ( oldProc As Ptr) as ptr

test.dll Todo is not the same with test2.dll ( have same api function name, different implement)
but call Todo() is the same Todo2() ,is xojo auto cache the functions?

You’ve got Alias backward. If both test.dll and test2.dll expose a function named Todo, then what you want is

'Declare Function Todo Lib "test.dll" ( oldProc As Ptr) as ptr
'Declare Function Todo Lib "test2.dll" alias "Todo2" ( oldProc As Ptr) as ptr

That allows you to call Todo() and use the one in test.dll, and call Todo2() and use the one in test2.dll.

Alias is the function name you use in your code. Soft declare will allow it to compile, but it will not function correctly.

so what I am doing is
function A(){
soft Declare Function Todo Lib “test.dll” ( oldProc As Ptr) as ptr
}
function B(){
soft Declare Function Todo2 Lib “test2.dll” alias “Todo” ( oldProc As Ptr) as ptr
}
Todo in test.dll msgbox “1”
Todo in test2.dll msgbox “2”

and now:

when I call B() then msgbox “2”
when I call A() then msgbox “1”
and then call B() ,will msgbox “1”…
and A(),B(),A(),B()…will always msgbox “1” from that on. why?

Soft just delays resolving the dll. It doesn’t differentiate them. Once one of the functions is loaded, it will always use that one, even if you have another soft declare with that name. Use Alias to give them different names.

so any idea if I want to load two dll to do it??thanks

Yes, you can. Use Alias to give them different names.

do you mean I have to change the dll function name?

I apologize. I had it wrong. Your original code should have worked. I don’t know why it didn’t.

sorry but original code not works fine… perhaps a bugs.

Could be, but since a declare definition is local in terms of use, why are you aliasing to the same function name? Wouldn’t it just be easier to leave them named the way they are in the original dll and use them that way?

I want to dynamic load some dll with same api in my situation… but If xojo couldn’t do this…
I will consider to write an common dll and use the common dll to load two same api dlls…

Basically you have two “methods” with the same name - regardless of the fact they come from two different dll’s.

Rather than try and load several different dll’s in the same scope (which is what you’re trying to do) I’d create a class that loads the dll and exposes the methods from that dll via methods on that class.
That way you could expose as many DLL’s as you wanted since each class instance would only refer to one DLL yet the class would expose the same api to the rest of your Xojo code.
I wrote about how to do this years ago in an article for http://www.xdevlibrary.com called Make a Plugin API for your REALbasic application

[quote=330792:@Norman Palardy]Basically you have two “methods” with the same name - regardless of the fact they come from two different dll’s.

Rather than try and load several different dll’s in the same scope (which is what you’re trying to do) I’d create a class that loads the dll and exposes the methods from that dll via methods on that class.
That way you could expose as many DLL’s as you wanted since each class instance would only refer to one DLL yet the class would expose the same api to the rest of your Xojo code.
I wrote about how to do this years ago in an article for http://www.xdevlibrary.com called Make a Plugin API for your REALbasic application[/quote]

thanks… I don’t know how to write a plugin as somany documents .but I can make a dll…I would like to do that in my dll to seperate several dlls.