[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

searching for a .dll and store the location not to search again

In order to get a programme startet written in VB6.0 I have to call a externall dll lets say "external.dll"

So I used the declare statement to set the entry point for the other programme

Declare Sub CALLDLL   Lib "d:\...\...\external.dll" Alias "_vbmainace@76" (ByVal........)

At several different locations in the VB programme I then can call the subroutine CALLDLL and execute the external dll. It all works fine on my machine the problem starts when I want to install this programme on different machines!!


Now my question:
In the moment I write the path were the "external.dll" is located into the programme code.
The problem is that the location of the "externall.dll" is not specified by default on the users machine.
In theory I only have to figure out the location when I install my VB programme on a different machine and from than it should not alter at all.

Is there any procedure to search automaticely for the "external.dll" file during installation and write the location with path into a special file ( or perhaps the registry ???) and than implement this location into the source code. So that the programme can execute the file without searching for the location every time it is running ???
0
themroc
Asked:
themroc
  • 11
  • 8
  • 3
  • +3
1 Solution
 
uncle_medCommented:


Why don't you use relative path. If you create a subfolder in the folder where your app resides you can use:

App.Path & "\FolderName\DllFile.Dll"

This way, no matter where your app is installed it will always look in the subfolder in the app folder.
0
 
themrocAuthor Commented:
The problem is that the "external.dll" can be anywhere on the machine were I am going to install my application.
So in a first step I have to search fro the location of this .dll file
0
 
uncle_medCommented:
So external.dll is not actually part of your installation. It can already be anywhere on your clent machine. Is that right?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
themrocAuthor Commented:
The problem is that the "external.dll" can be anywhere on the machine were I am going to install my application.
So in a first step I have to search fro the location of this .dll file
0
 
themrocAuthor Commented:
That is exactly right, "external.dll" is already on the client machine before installation. So in a first step I have to locate this file and then I have to write the location somewhere to avoid searching for it every time I run my programme
0
 
uncle_medCommented:
If your DLL is a com dll then windows automatically looks in your app directory and also system (ofcourse the dll must be registered).
If its not, I guess you have to search the whole disk.
Have you thought about including the dll in your installtion routine. That way you will always know where the dll is going to be. The down side is that clients will probably end up with 2 copies of the dll, but surely that's not a big problem.
0
 
themrocAuthor Commented:
Because the .dll is part of a comercial programme I did not dvelope I think it is not possible to distribute the .dll a second time. I think I would not mind to search the whole disk. The problem is more that the client has to search during installation. Then the search result has to be writen in a location were I can access it easily everytime I run my programme.
0
 
gencrossCommented:
Here is an idea.  When you start your app on the users machine do a search in the most common places where it usually is.  If it is not there then do a full search.  Once you have the file location write it to an INI file in the app.path.  Next time your program starts you will have it.  You can use the below INI API functions to read and write the INI file.

FYI...If you do not list the location of your dll, I believe windows will look in the Windows\system directory for the dll first, and then I believe the Windows directory.  It does this by default so if the DLL is in the windows\system or windows directory it should be able to find it without you doing anything.

Paste this code in a module in your app.

'Declares
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias _
    "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString _
    As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias _
    "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
'----------------------------------------------------

'Functions
Public Function ReadINI(SectionName As String, LeftOfEqual As String, ReturnVar As Variant, TheAnswer As String, BufferSize As Integer, INIFilePath As String) As Long

        cReturnLng = GetPrivateProfileString(SectionName, LeftOfEqual, ReturnVar, TheAnswer, BufferSize, INIFilePath)
        ReadINI = cReturnLng
       
End Function
Public Function WriteINI(SectionName As String, LeftOfEqual As String, RightOfEqual As String, INIFilePath As String) As Long

    WriteINI = WritePrivateProfileString(SectionName, LeftOfEqual, RightOfEqual, INIFilePath)
   
End Function
0
 
gencrossCommented:
I am trying to think of a better way for you to do this.  I do not think you can use a variable in a declare, which means you cannot pass it a path.

When you find the file you can make a copy of it into the windows\system dir or your app dir then you do not have to store the name anywhere or change any code.  Copying the file shouldn't do any harm except if the external program is ever updated you will want to make sure you get the new copy of the dll.

Here is file search routine.  There are many others on PSC you can search for as well.

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=14249&lngWId=1

0
 
gencrossCommented:
You will want to test this of course on your machine.  Copy this file to a different dir and call it from there just to be sure it is not dependent on another file in the directory or something.
0
 
egsemsemCommented:
Did you try writing "external.dll" only with no path, for example:
    Declare Sub CALLDLL Lib "external.dll" Alias "_vbmainace@76" (ByVal........)
If 'external.dll' is registered properly on the client System, I think windows will find its path correctly. And if this method didn't succeed, try to add a refrence to 'external.dll' in your project instead of using declare function, it might succeed.



thanks,

Osama

0
 
themrocAuthor Commented:
If I write external.dll only into the declare function than it coemes up with the message "File not found"

How do I add a reference to "external.dll" instead of using the declare function ???
0
 
themrocAuthor Commented:
If I write external.dll only into the declare function than it coemes up with the message "File not found"

How do I add a reference to "external.dll" instead of using the declare function ???
0
 
gencrossCommented:
It does not sound like this is a COM component and therefore cannot be registered and referenced.  If it was a COM component you never would have used Declare to begin with.  If there was documentation that came with the dll, and if it told you to declare the dll then it is not a COM component and a reference will not work.

If you would like to try to register the dll just in case here is how.

At a command prompt type regsvr32 c:\external.dll (or path to dll)

If you get an error, and the software that uses the dll works correctly, of course, then this is not a COM component and you must use DECLARE.
0
 
themrocAuthor Commented:
thanks,
I tried and got the message:
was loaded but the DLLRegister Service entry point was not found. DLLRegister Service may not be exported, or a corrupped version of "external.dll was in memory.
Consider PView to detect and remove it
__________

Im not sure how to interpret this, but one think is clear the dll is not corrupt. So I think it is not a proper COM component.

Im not quiet sure what to do next ???


0
 
gencrossCommented:
Have you tried my comment above about finding the file on the machine and copying it to a directory?

The easiest is probably to distribute this file with your app in the same directory so when you install your file this file is installed as well.

You can write code that looks for the file in the app.path.  If it cannot find it then copy it from a network drive someonewhere.

You could also run the file from a network drive.  I don't know if declare statements support UNC names (\\Server\path) so everyone should have the same drive mapping if you do this.


0
 
themrocAuthor Commented:
In the moment I think the best will be  to distribute the file with the application.

I will wait a little bit till closing the question,
perhaps someone else comes up over night with a brilliant idea.
Thanks a lot so far !!!!!!

themroc
0
 
gencrossCommented:
:)
0
 
themrocAuthor Commented:
In the moment I think the best will be  to distribute the file with the application.

I will wait a little bit till closing the question,
perhaps someone else comes up over night with a brilliant idea.
Thanks a lot so far !!!!!!

themroc
0
 
gencrossCommented:
Just thought of something else.  When you distribute the file place it in the Windows\system or Winnt\system32 (or whatever the system directory is).  This way you do not need to hard code a path in the Declare.  You can then declare like this and the app will find the file...

Declare Sub CALLDLL Lib "external.dll" alias "_vbmainace@76" (ByVal........)

This will be of benefit if you want to change the directory of your application code will not have to change.
0
 
themrocAuthor Commented:
Final distribution of points

I'm a little bit in a dilema,
Gencross did a lot of support and Im very gratefull for this but in the end we came up with the solution uncle med alredy proposed. Is there a way to share points?

Because to be fair I think I have to give the points to uncle med??
0
 
ArkCommented:
Hi
Take a look on my code at http://www.freevbcode.com/ShowCode.Asp?ID=1863
>>This advanced module allows you to call API functions by name without declaring and to return values from them. It uses Assembly Language within VB code to accomplish this task.<<

With this code you can call your dll dinamically, without declarations.

Cheers
0
 
gencrossCommented:
You can split the points by asking community support to lower the points on this question by half then accept an answer to the question.  Post another question with title of "Points for...".  One of us will comment on it and you accept the comment as an answer.

0
 
ComTechCommented:
As per request in Community Support, the points have been lowered for a split.

Thanks,
ComTech
CS Admin @ EE
0
 
themrocAuthor Commented:
In the end I went for this solution,
its not optimum but it solved the problem so far
thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 11
  • 8
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now