|
-
Jun 26th, 2003, 06:33 AM
#1
Thread Starter
Hyperactive Member
Loadlibrary / Declaring dll function at runtime
My software uses a Can serial card. I need to support three different types of card (PCMCIA, PCI, USB) each of these have there own dll. The dll's all contain the same function / function names.
At the moment I have to get all the users to rename their dll file to 'cancard.dll' then I am using:
VB Code:
Declare Function CANPC_reset_board Lib "cancard.dll" Alias "_CANPC_reset_board@0" () As Long
to delcare the function(s).
I want to get away from forcing the user to rename their DLL's and automatically detect their dll and delcare it at runtime.
I briefly looked at LoadLibrary, but it appears you need to use CallWindowProc to call the function. I still want to use the same syntax as before e.g
VB Code:
dim err_code as long
err_code = CANPC_reset_board
Any ideas?
Cheers
Last edited by Rick H; Jun 26th, 2003 at 07:41 AM.
-
Jun 26th, 2003, 07:57 AM
#2
Create an alias for each dll and call the appropriate aliased function at runtime.
-
Jun 26th, 2003, 08:00 AM
#3
Thread Starter
Hyperactive Member
Have you got an example of how to do this?
Cheers
-
Jun 26th, 2003, 08:09 AM
#4
VB Code:
Declare Function CANPC_reset_board_pmcia Lib "cancard.dll" Alias "_CANPC_reset_board@0" () As Long
Declare Function CANPC_reset_board_pci Lib "cancrd2.dll" Alias "_CANPC_reset_board@0" () As Long
Declare Function CANPC_reset_board_usb Lib "cancrd3.dll" Alias "_CANPC_reset_board@0" () As Long
Note that I don't know what the real names of the dlls are - you'll have to edit that..
-
Jun 26th, 2003, 08:14 AM
#5
Thread Starter
Hyperactive Member
Thats an idea, though they would normally only have one of the DLLs one their PC so the other declares would cause an error.
-
Jun 26th, 2003, 08:39 AM
#6
Thread Starter
Hyperactive Member
Actually it might work, the declarations don't cause an error unless I call the function and the dll doesn't exist. I can check which dll exists at runtime then use this:
VB Code:
private const PCMCIA = 1
private const PCI = 2
private const USB = 3
private cardtype as byte
public function CanPc_reset_board() as long
select case cardtype
case PCMCIA
CanPc_reset_board=canpc_reset_board_pcmcia
case PCI
CanPc_reset_board=canpc_reset_board_pci
case USB
CanPc_reset_board=canpc_reset_board_usb
end select
end sub
-
Jun 26th, 2003, 09:59 AM
#7
Frenzied Member
Just trap the error and use it to determine that the dll doesn't exist, maybe?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|