Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declare Function Question

Status
Not open for further replies.

woogoo

Programmer
Feb 14, 2004
247
GB
Hi All,

In one of my applications I use a 3rd Party DLL that uses the 'Declare Function' statement for importing the DLLs functions, but my problem lies in the fact that I need to support two versions of the DLL.

At present with the exception of the DLL's name the Declare statements are identical, so I use a custom compiler switch to build with the appropriate version of the DLL.

What I'd like to know is if there is any way I could have my application support both of these versions within the same runtime, allowing the user to make use of either one.

FYI, When our application is installed I also install the 3rd party's DLL as part of this process.

I'd appreciate your thoughts on this one and I'd be interested to hear from anyone that has found a solution, or who could point me in the right direction.


woogoo
 
What I'd like to know is if there is any way I could have my application support both of these versions within the same runtime, allowing the user to make use of either one.
You should be able to either through Reflection or an Interface. Maybe not the best thread on reflection, but the one I know where it is. :) thread796-1463398. As to an Interface I have no clue.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Hi Sorwen, thanks for the response, but this approach won't work as there is no Assembly information associated with the DLL, as it's an 'old style' C DLL using dllexport __cdecl for the function exports.

As regards the Interface option I don't think this is a worker either as I'm not to sure how I can implement this:

Code:
Private Declare Function ClearPointers Lib "A_Dll_v3.dll" Alias "ClearPtrs" (ByVal pEnv As Int64) As Int64

Private Declare Function ClearPointers Lib "A_Dll_v5.dll" Alias "ClearPtrs" (ByVal pEnv As Int64) As Int64

If you look at the code the only thing that changes is the name of the DLL, so it looks like it's back to the drawing board for me, unless anyone knows different.

One though that did cross my mind and that was a Platform Invoke using a wrapper class but I can't do this as I'm unable to change the DLL in question as it's not available within the dllattributes class.

Oh hum!



woogoo
 
I re-read your first post and I think I got a little confused. The way it sound at first was that the dll used the declare not your program. But you did say you compile the dll. So how many dlls are we talking about. Do you have a dll that uses a 3rd party dll that uses A_DLL_v3.dll or is A_DLL_v3.dll the 3rd party dll and you have a dll that uses it? I was going to make suggestions, but let me get that straight first.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Hi, sorry for the confusion Sorwen, I'll try to explain a bit better. I have a VB Class that contains these types of declarations:
Code:
#If XYZ_DLL = 3 Then
Private Declare Function ClearPointers Lib "A_Dll_v3.dll" Alias "ClearPtrs" (ByVal pEnv As Int64) As Int64
#Else
Private Declare Function ClearPointers Lib "A_Dll_v5.dll" Alias "ClearPtrs" (ByVal pEnv As Int64) As Int64
#End If
As you can see from the above the version of the 3rd Party DLL used is controlled by a custom compiler flag, and as a result will generate one of two versions of the DLL.

What I was wanting to be able to do was to have a version of MY DLL that could support either v3 or v5 of the imported DLL removing the need for the compiler flag.

I know what version of the 3rd Party DLL I need by the configuration file I use to create the environment, so I can set a flag within MY DLL that would allow my code to use the proper version of the 3rd Party DLL when called.

However, what I'm not to sure is how to implement this in code to get something like this:
Code:
Dim MyDLL as WrapperDLL = New WrapperDLL()
MyDLL.SetVersion = EnvCfg.GetVersion()
MyDLL.DoSomeAction()
So when SetVersion is set with 3 for example DoSomeAction() would call into the v3 DLL or if set with 5 it would use v5 of the DLL.

I hope this has made things clearer and hasn't muddied the waters for you.

Thanks.

woogoo
 
1) What version of VB.Net/Visual Studio are you using?

2)
I have a VB Class that contains these types of declarations:
VB or VB.Net?

3)
Code:
Dim MyDLL as WrapperDLL = New WrapperDLL()
MyDLL.SetVersion = EnvCfg.GetVersion()
MyDLL.DoSomeAction()
You want to pass the version to your dll? Then DoSomeAction will call either v3's or v5's ClearPtrs?

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
I'm using Visual Studio 2008 .NET v3.5 VB v9 and developing for an x64 architechture.

Passing the Version No. to the DLL is an option and is probably a better idea than .SetVersion()

Does this help?
--


woogoo
 
Yes and no. Lets try this another way. Here is a thought.

Code:
Public Class SomeClass
    Private Declare Function ClearPointersV3 Lib "A_Dll_v3.dll" Alias "ClearPtrs" (ByVal pEnv As int64) As int64
    Private Declare Function ClearPointersV5 Lib "A_Dll_v5.dll" Alias "ClearPtrs" (ByVal pEnv As int64) As int64

    Private dllVersion As String

    Public Sub New(ByVal version As String)
        dllVersion = version
    End Sub

    Public Sub DoSomeAction()
        'Whatever code

        If dllVersion = "3" Then
            RetVal = ClearPointersV3(PassNumber)
        ElseIf dllVersion = "5" Then
            RetVal = ClearPointersV5(PassNumber)
        End If

        'More whatever code
    End Sub

    'Whatever other code your class does.
End Class

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top