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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling same function from different DLL's "NT".DLL "95".DL 1

Status
Not open for further replies.

aclayborne

Programmer
May 3, 2000
49
US
I have a function that resides in two different DLL's "app95".dll and "appNT".dll. I'm not sure which will be there, it depends on the operating system. But in my BAS I have:
Declare Function ABC LIB "appNT".dll
But if I install my app on a 95/98 machine appNT.dll won't be there. Function ABC will reside in "app95".DLL.

How can I work around this in the declarations and code.

Acie Clayborne
 
Declare the API function with two different aliases and then at run time, check the OS version and call the appropriate function.

for example . . .

Code:
Declare Function ABC LIB "app95".dll Alias "ABC9x"
Declare Function ABC LIB "appNT".dll Alias "ABCNT"




- Jeff Marler B-)
 
Declare Function ABC LIB "app95.dll" Alias "ABC9x"
Declare Function ABC LIB "appNT.dll" Alias "ABCNT"
gets you an "Amiguous Name" error.

The following "wraps" the function.
Code:
'* Module/Class Declaratives
Declare Function ABC95 LIB "app95.dll" 
Declare Function ABCNT LIB "appNT.dll"
Private blnTested as boolean
Private bln95     as boolean
Function ABC()
    if blnTested = false then
       '* On-Time test for NT
        blnTested = true 
        On error resume next
            ABC = ABCNT
            if err.Number = 0 then exit Function
            bln95 = True
        On error goto 0
    End if           
    If bln95 then
        ABC = ABC95
    else
        ABC = ABCNT
    end if
End Function
 
OPPS . . . John is right! I put the name in the wrong spot (Sorry . . . I was having "a day" yesterday). The idea remains the same however . . . you want to have 2 different names for the functions, determine the OS at run time and then call the appropriate function . . . I would recommend using the API declares that John listed. However, to get the correct operating system, use the GetVersionEX API rather than an error trap. The API declaration is as follows . . .

Code:
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long



- Jeff Marler B-)
 
For those who are interested, the Alias tag is for exported function names that differ from the name used in the declare. - Jeff Marler B-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top