Results 1 to 7 of 7
  1. #1
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Copy a dll to folder (A97 SR2)

    History of Project
    I have created a database that revolves around housing properties and photographs of said property. I have a set of guys who go out and take photos of a property and then return and download the photograph onto the PC. They then go into the database and reference the property address to the photograph ( which still sits in the external folder).

    I created this database and used a third party dll file to allow them to do a search through the c: drive directory. You can only do this if you have installed the dll file to your Windows/system folder. It all works fine and I am pleased with the result.

    The problem

    You can only view or make changes to the database photo's if you have this dll file installed. If a person enters the database from another PC and cannot view the files because they do not have the file can I create a piece of code that copies the dll file (which will sit in the same folder as the database), copy it and then paste it into the windows/system folder? If so, can anyone show me the code. <img src=/S/crossfingers.gif border=0 alt=crossfingers width=17 height=16>
    Jerry

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copy a dll to folder (A97 SR2)

    There are some issues that should be resolved before providing code:

    (1) You state that it is a third-party DLL. Does the license allow you to copy it to other PC's?
    (2) Usually, a DLL must be registered in the Windows registry; just copying it may not be enough. Have you checked this?

  3. #3
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Copy a dll to folder (A97 SR2)

    Hi Hans
    1) Yes, the coder has agreed as long as I keep the headers in his code attributing it to him
    2) When I set it up it was just a copy and paste job no need for the registry to be updated

    Whilst waiting for your reply, I had an idea that I could put the dll into a self extracting zip file in the database folder and when the database opens it checks if the file is in the systems folder, if not spark up the exe to download it. Is my logic right?

    Jerry
    Jerry

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copy a dll to folder (A97 SR2)

    OK, in that case it shouldn't be too hard. If the location of your database is fixed, you can hard-code the path into the code. Otherwise, you can retrieve the path from the name of the current database. Here is code for the fixed location - adapt the path and file names as needed:

    Put the following declaration in a standard module:

    Declare Function GetSystemDirectory Lib "kernel32" _
    Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

    Call the following procedure in the OnLoad of your startup form, or call it from an AutoExec macro:

    Sub CopyDll()
    Dim strName As String
    Dim strSource As String
    Dim strTarget As String
    Dim lngRet As Long

    ' Path of database
    strSource = "PatabaseDir"

    ' Create a buffer
    strTarget = Space(255)
    ' Get the system directory
    lngRet = GetSystemDirectory(strTarget, 255)
    ' Remove all unnecessary Chr(0)'s
    strTarget = Left(strTarget, lngRet)

    ' Name of DLL
    strName = "MyUtility.dll"

    ' If DLL not found in system directory, copy it from database directory
    If Dir(strTarget & "" & strName) = "" Then
    FileCopy strSource & "" & strName, strTarget & "" & strName
    End If
    End Sub

  5. #5
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Copy a dll to folder (A97 SR2)

    Thanks Hans

    Works like a treat. Have a great weekend

    Jerry
    Jerry

  6. #6
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Copy a dll to folder (A97 SR2)

    Hans

    One other thing. Due to the size of the database and associated folder of graphics the powers that be would like to put the database on a removable hard disk which connects via the USB. The code you provided me with is great if it is sitting on a fixed disk as I can set StrTarget and strSource. If, on the other hand I insert a removable hard disk the computer to where it is connected to assigns a Drive letter, this will vary from machine to machine depending on what is installed on it ie CDRW, CD, slave drives etc. This will obviously effect StrSource, at the moment (for test purposes) I have set it as c:windowsdesktop, is there a way I can change this so it is more flexible and can find out automatically what drive letter the database is on and make the first part of the string as a variable ie H:.... or Z:.....?
    Jerry

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copy a dll to folder (A97 SR2)

    Hi Jerry,

    Put the following routine in a standard module. It extracts the file path from the specified full name

    Function GetPath(strName As String) As String
    Dim i As Integer
    If InStr(strName, "") = 0 Then Exit Function
    i = Len(strName)
    While Mid(strName, i, 1) <> ""
    i = i - 1
    Wend
    GetPath = Left(strName, i - 1)
    End Function

    You can use this function to obtain the path to the database:

    strSource = GetPath(CurrentDb.Name)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •