Colliding declares?

I have a situation where i’m working with two DLLs, which are named differently, and communicate with two distinct pieces of hardware. They are from one company and the dlls share some common code libraries.

they have a lot of functions with the same name. I can work with either one, but when I work with both, the functions seem to cross wires even though I can trace my code to see that each one is routed to the correct declare (pointing to the correct DLL).

The hardware vendor tells me that they have their own examples, coded in a different environment, that does not replicate this issue.

I tried aliasing the functions too, but that didn’t work.
Can anyone suggest anything else to look at?

It should, based on your description

Declare Function LIB1_functionname Lib "Lib1.dll" Alias "functionname" () As Integer
Declare Function LIB2_functionname Lib "Lib2.dll" Alias "functionname" () As Integer

This has come up a couple of times recently and it is a bug / limitation. Feedback: 63334

I think the only solution at the moment is to use the MBS plugin DeclareLibraryMBS class.

1 Like

Please check DeclareLibraryMBS and DeclareFunctionMBS classes as those allow multiple libraries defining the same named function.

1 Like

and yet it doesn’t work…

Yes, I will do this.
I’m a bit nervous about the amount of effort to translate my declares to use your plugin. I haven’t made use of your declare functions before.

Glad to know there is a solution.

I’ve replicated the issue, <> updated with a simple example.

Well, you may use delegates defined in Xojo, assign the ptr you got for the function and call it this way.
Lot’s of possibilities.

Here example, which uses DeclareLibraryMBS with either DeclareFunctionMBS to call it or a Xojo delegate:

// change path if you like to try this on Windows or Linux
Dim d As New DeclareLibraryMBS("/usr/lib/libz.1.dylib")

// zlibVersion
// ZEXTERN Const char * ZEXPORT zlibVersion Of((void));

Dim p As ptr = d.Symbol("zlibVersion")

// call via our class:
Dim f As New DeclareFunctionMBS("()Z", p)
Dim n As String = f.Invoke
MsgBox "zlibVersion: "+n

// call via delegate
' define delgate like this:
' Public Function zlibVersionDelegate() As CString

Dim z As New zlibVersionDelegate(p)
Dim v As String = z.Invoke
MsgBox "zlibVersion: "+v

I see that @William_Yu has made a new ticket regarding soft declares and has marked that is fixed (nice) <>, not really sure why there’s a new ticket when <> exists, I can only assume that compile time declares aren’t going to be fixed at this time?

Not necessarily, but it does buy us some more time if Soft Declares becomes a viable workaround for the time being.

1 Like