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

Calling a DLL

Status
Not open for further replies.

kliz0328

Programmer
Nov 7, 2005
138
US
I am modifying an existing program that calls a couple of DLL's with the following snippets of code.
Code:
Private Declare Sub LEASE_CHECK _
  Lib "c:\work\TimeCounting3-23-06\lease.dll" _
  Alias "LEASE_CALC" _
  (inrec As in_record, DataRec As data_record, outrec As out_record, InFeeRec As in_fee_record)
Code:
Private Declare Sub LOAN_CALC Lib "c:\work\TimeCounting3-23-06\Lnb1184b.dll" _
  (inrec As in_record, outrec As out_record, fee_inrec As fee_inrecord, data_rec As data_record)

Notice that they are both using a string constant for the Lib statement. I looked aorund on here to try and make this call more dynamic and it said to just put the file name and VB will look for it in the current folder. I tried this and the top one completely errored out and said it couldn't find it, and the second one did not produce an error, but it was obivous, by the lack of activity, that the DLL was not getting called. Is there anything I can do to make these calls dynamic, so when I send the program to a client they do not have to make an exact folder path for the app to work?
 
You cannot specify a variable file name for Lib clause in Declare statement.

If the location of the DLL file is not known in advance, you can change the current working directory and drive before you call the API function for the first time in your program. VB only locates the file once when the function is called for the first time. After that the DLL file is loaded in memory and all subsequent function calls work even if the current working directory or drive is changed.

Your declarations will go without any folder name. The only thing you need to care about is that before calling the API function for the first time, you switch your current working drive and directory to the folder where DLL files are placed.
___
[tt]
Private Declare Sub LEASE_CHECK Lib "lease.dll" Alias "LEASE_CALC" (inrec As in_record, DataRec As data_record, outrec As out_record, InFeeRec As in_fee_record)

Private Declare Sub LOAN_CALC Lib "Lnb1184b.dll" (inrec As in_record, outrec As out_record, fee_inrec As fee_inrecord, data_rec As data_record)
...
'calling the API function for the first time.
ChDrive "C" 'switch to C drive
ChDir "C:\Work\TimeCounting3-23-06" 'switch to this folder

Call LEASE_CHECK(...)
Call LOAN_CALC (...)[/tt]
___

The drive and folder passed to ChDrive and ChDir functions are of course variables, allowing you to place the DLL files in any folder you want.
 
Sorry to be such a newbie, but I am taking this project over form someone else, and am not sure where or what the API function is, would it be in one of the forms, or one of the .bas files?
Also when specifying do I have to specify the ChDrive, or can I just do this

ChDir App.Path
 
I tried the dynamic link and made the .exe.local folder but nothing changed, it tried to run but could not find the dll? This is so weird, I look at other apps we have and they run fine with just the filename as the Lib string???????????????????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top