Results 1 to 17 of 17

Thread: [RESOLVED] Refer to spefic dll

  1. #1

    Thread Starter
    Lively Member okosv's Avatar
    Join Date
    Sep 2006
    Posts
    95

    Resolved [RESOLVED] Refer to spefic dll

    Hi All,
    As I know, when I declare functions from DLL, like this:
    Code:
    Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
    If refer to system dll

    When I declare function like this:
    Code:
    Private Declare Function MyFunc Lib "test.dll" Alias "DLLMyFunc" (ByVal lpText As String) As Long
    I refer to test.dll file which may be located in app folder or in system folders (windows, windows\system32 etc.)
    If test.dll located in app folder and system folder too, to which dll VB would refer?
    How can I refer to specfic dll? For example, only for DLL, which located in app folder, event such dll is located in system folder too
    Thanks all

    P.S. Sorry for my eng )))

  2. #2
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Refer to spefic dll

    Ah yes, this is really the interesting question. I do not know. LOL . I vaguely remember reading a post about it, i believe it checks the System32 folder first. Anyway, I guess you can try to "break" you app by changing the current directory via:

    vb Code:
    1. Private Declare Function GetCurrentDirectory Lib "kernel32.dll" Alias "GetCurrentDirectoryA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    2. Private Declare Function SetCurrentDirectory Lib "kernel32.dll" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long

    Lemme look this up.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Refer to spefic dll

    Here is the search order for DLLs.

    VB delay loads DLLs in most cases and when this is the case, the delay-loaded DLL is not loaded until it is first called. I think that if you ensure the DLL you want to use is in your app's path then it will be used since that is the first path searched. If you want to use the system folder (3rd path in search order), you may want to rename the DLL in your app.path if it exists there.

    Another option could be to explicitly load the DLL via LoadLibrary API. If done, you probably should call FreeLibrary API when your app unloads. I don't know if VB calls FreeLibrary if it didn't load the DLL.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Lively Member okosv's Avatar
    Join Date
    Sep 2006
    Posts
    95

    Re: Refer to spefic dll

    Thanks 4all!

    2LaVolpe:
    In above link:
    Search Path Used by Windows to Locate a DLL


    With both implicit and explicit linking, Windows first searches for "known DLLs", such as Kernel32.dll and User32.dll. Windows then searches for the DLLs in the following sequence:

    The directory where the executable module for the current process is located.

    The current directory.

    The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.

    The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.

    The directories listed in the PATH environment variable.
    It mean's that at first system try to find it in app folder, isn't it?
    Renaming is not correct way.
    Because I'm using special dll which contains functions for protecting app from copying
    Pro Users may replace this dll with another dll, without protecting functions
    Of course, I'm also checking MD5 or CRC of this dll, before checking protection

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Refer to spefic dll

    That is exactly how I interpret it. App.path is the first folder searched.
    If someone deleted your DLL from the app.path then that is easy enough to check and you can abort your app. If it is there, you can crc and abort if crc is not the same. I guess those would be valid options.

    When I suggested maybe renaming. What I meant is that if you wanted to prevent the one in your app.path from running, renaming it would prevent it from being the 1st found, then the other paths would be searched and, if found in those other paths, that one would be used instead.

    To prevent potential problems, I'd suggest that the DLL always be installed in the exe's folder. But what if someone moved the exe to another folder?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Refer to spefic dll

    Quote Originally Posted by okosv
    It mean's that at first system try to find it in app folder, isn't it?
    As LaVolpe said, App.Path is good enough for VB programmers.

    On a technical level though, the "Executable Module Directory" and the "Current Directory" can differ. This is for people who manually link to DLLs/EXEs themselves for operations like Resource management (Ex: extracting Icons and converting them to GDIPlus Images ) and [Un]Registering ActiveX controls at runtime via:

    vb Code:
    1. LoadLibrary
    2. GetProcAddress ("DllRegisterServer" or "DllUnregisterServer")
    3. CallWindowProc
    4. FreeLibrary

    If you want to see the mod dir and current dir differ, run this:
    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function Module32First Lib "kernel32.dll" (ByVal hSnapshot As Long, ByRef lppe As MODULEENTRY32) As Long
    4. Private Declare Function GetCurrentDirectory Lib "kernel32.dll" Alias "GetCurrentDirectoryA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    5. Private Declare Function SetCurrentDirectory Lib "kernel32.dll" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
    6. Private Declare Function CreateToolhelp32Snapshot Lib "kernel32.dll" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
    7. Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
    8. Private Declare Function GetCurrentProcessId Lib "kernel32.dll" () As Long
    9.  
    10. Private Const MAX_PATH          As Long = 260
    11. Private Const TH32CS_SNAPMODULE As Long = &H8
    12. Private Const MAX_MODULE_NAME32 As Long = 256
    13.  
    14. Private Type MODULEENTRY32
    15.     dwSize        As Long
    16.     th32ModuleID  As Long
    17.     th32ProcessID As Long
    18.     GlblcntUsage  As Long
    19.     ProccntUsage  As Long
    20.     modBaseAddr   As Long
    21.     modBaseSize   As Long
    22.     hModule       As Long
    23.     szModule      As String * MAX_MODULE_NAME32
    24.     szExeFile     As String * MAX_PATH
    25. End Type
    26.  
    27. Private Sub Form_Load()
    28.     Dim udtME32 As MODULEENTRY32, lRet As Long, hTH32SS As Long, szCurrentDir As String, szModDir As String
    29.    
    30.     ' Change the current directory for this process to the parent folder
    31.     lRet = SetCurrentDirectory("..")
    32.    
    33.     ' Get a snapshot of the Modules for the current application
    34.     hTH32SS = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId())
    35.     ' Init the size so windows know what this struct is
    36.     udtME32.dwSize = Len(udtME32)
    37.     ' The first module is the current application
    38.     lRet = Module32First(hTH32SS, udtME32)
    39.     ' Cleanup
    40.     lRet = CloseHandle(hTH32SS)
    41.    
    42.     ' Get the module directory
    43.     szModDir = Left(udtME32.szExeFile, InStrRev(udtME32.szExeFile, "\") - 1)
    44.    
    45.     ' Get the current directory for the process
    46.     szCurrentDir = String(MAX_PATH, Chr(0))
    47.     lRet = GetCurrentDirectory(MAX_PATH, szCurrentDir)
    48.     szCurrentDir = Left(szCurrentDir, lRet)
    49.    
    50.     ' Output info
    51.     Debug.Print "Module Directory : " + szModDir
    52.     Debug.Print "Current Directory: " + szCurrentDir
    53.    
    54.     ' End App
    55.     Call Unload(Me)
    56. End Sub

    Example output:
    Code:
    Module Directory : C:\Program Files\Microsoft Visual Studio\VB98
    Current Directory: C:\Program Files\Microsoft Visual Studio
    Fuel the brain.

  7. #7

    Thread Starter
    Lively Member okosv's Avatar
    Join Date
    Sep 2006
    Posts
    95

    Re: Refer to spefic dll

    ok, thanks a lot
    but another question
    How can I detect path of registered ActiveX control, which used in app
    I wan't to do it, 'cause
    Before using ActiveX control, I would detect path, then check MD5 or CRC of control's file
    then continue running
    It's control used for protecting app from illegal copying
    Advanced users way replace original ActiveX control for unoriginal ActiveX control

  8. #8

    Thread Starter
    Lively Member okosv's Avatar
    Join Date
    Sep 2006
    Posts
    95

    Re: Refer to spefic dll

    up...

  9. #9
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Refer to spefic dll

    To retrieve info about OLE components, you need to examine HKEY_CLASSES_ROOT in the registry.

    For example, my ActiveX Control, has the full project name of:
    Code:
    X3Button.ucX3Button
    So it's located in:
    Code:
    HKEY_CLASSES_ROOT\X3Button.ucX3Button
    The ClassID (aka CLSID) is located in the Classname subkey:
    Code:
    HKEY_CLASSES_ROOT\X3Button.ucX3Button\CLSID
    Information about the control is in:
    Code:
    HKEY_CLASSES_ROOT\CLSID\{VALID CLSID}
    Hope this helps
    Attached Images Attached Images  
    Attached Files Attached Files

  10. #10

    Thread Starter
    Lively Member okosv's Avatar
    Join Date
    Sep 2006
    Posts
    95

    Re: Refer to spefic dll

    Thanks a lot,
    I found some sample for accessing COM classes via WMI
    For example, list installed COM classes for ActiveLock:
    Code:
    On Error Resume Next
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_COMClass where Caption LIKE '%ActiveLock3%'",,48)
    For Each objItem in colItems
        Wscript.Echo "Caption: " & objItem.Caption
        Wscript.Echo "Description: " & objItem.Description
        Wscript.Echo "InstallDate: " & objItem.InstallDate
        Wscript.Echo "Name: " & objItem.Name
        Wscript.Echo "Status: " & objItem.Status
    Next
    Is there way to detect file path of this control?

  11. #11
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Refer to spefic dll

    Quote Originally Posted by okosv
    Is there way to detect file path of this control?
    I believe it's the InprocServer32 key. Look at my app again and select ActiveLock. It should be in the list.

    EDIT:
    I don't know what WMI is, but if there is'nt a path property/function, the you might have to use registry functions which are kinda easy to get.
    Last edited by Xiphias3; Sep 16th, 2009 at 01:12 PM.

  12. #12

    Thread Starter
    Lively Member okosv's Avatar
    Join Date
    Sep 2006
    Posts
    95

    Re: Refer to spefic dll

    2Xiphias3:
    Thank u, I can get file wich binded to ActiveX control in your code
    But may be user from which name the app is started, can't have access for registry
    Therefore I search another way

  13. #13

    Thread Starter
    Lively Member okosv's Avatar
    Join Date
    Sep 2006
    Posts
    95

    Re: Refer to spefic dll

    I have found solution, VBScript code:
    Code:
    Option Explicit
    Dim objWMIService, objCOMClassItems, objCOMClassItem
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set objCOMClassItems = objWMIService.ExecQuery("Select * from Win32_ClassicCOMClassSetting where Caption LIKE '%ActiveLock%'",,48)
    For Each objCOMClassItem In objCOMClassItems
        WScript.Echo "Caption: " & objCOMClassItem.Caption
        WScript.Echo "ComponentId: " & objCOMClassItem.ComponentId
        WScript.Echo "Description: " & objCOMClassItem.Description
        WScript.Echo "InprocServer (file): " & objCOMClassItem.InprocServer32
    Next
    Set objCOMClassItem = Nothing
    Set objCOMClassItems = Nothing
    Set objWMIService = Nothing
    Here is some useful links about this problem:
    List installed COM objects and associated ProgIDs
    http://www.scriptinternals.com/new/u...assSetting.htm

    If somebody has a better decision, I'll wait
    Thanks all

  14. #14
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: [RESOLVED] Refer to spefic dll

    Glad you're all good!!!

    Quote Originally Posted by okosv
    But may be user from which name the app is started, can't have access for registry
    I doubt this. All you're doing is reading the registry. If the user cant read the registry, when the app is running how would it know what Object to instantiate when it can't get the relevant GUID/CLSID and the path (usually from InprocServer32). Remember, ActiveX controls are only required to be registered at the point before of instantiation, hence why registering controls at run-time will work (though not recommended). The information about COM is stored in the registry. So, as far as I know, whatever route you take, you need to read from the registry. Correct me if I'm wrong.

    A
    Quote Originally Posted by Xiphias3
    I believe it's the InprocServer32 key.
    B
    Quote Originally Posted by okosv
    Is there way to detect file path of this control?
    C
    Quote Originally Posted by okosv
    WScript.Echo "InprocServer (file): " & objCOMClassItem.InprocServer32
    Reasons like this is why I always try to find or make my own type library and utilize the Watch window as much as I can. I made a somewhat long rant about the HTML Type library in another thread, and told the guy to reference they HTML Obj lib and declare his variables properly using the relevant DataTypes rather than Varianting everything.

    I decided to look into this "WMI" and no surprise found a TypeLib and pumped out all the properties. Gotta love it when dot-notation shows something. For anyone interested in using WMI in VB6, then check out:
    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

    Also, here's how to use VB6 to get ALL the information by enumerating the properties and not missing out because you don't know the actual property name (as seen above, it was InprocServer32).

    TypeLibrary:
    Code:
    Microsoft WMI Scripting V1.2 Library
    System32\wbem\wbemdisp.tlb
    Code:
    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim oWMIService As WbemScripting.SWbemServices, oCOMSet As SWbemObjectSet, oCOM As SWbemObjectEx, _
    5.         oProp As SWbemProperty
    6.    
    7.     Set oWMIService = GetObject("winmgmts:\\.\root\cimv2")
    8.     Set oCOMSet = oWMIService.ExecQuery("Select * from Win32_ClassicCOMClassSetting where CAPTION LIKE '%X3Button%'")
    9.  
    10.     For Each oCOM In oCOMSet
    11.         For Each oProp In oCOM.Properties_
    12.             If (Not IsNull(oProp.Value)) Then
    13.                 Debug.Print Left(oProp.Name + String(16, " "), 16) + ": " + CStr(oProp.Value)
    14.             End If
    15.         Next oProp
    16.     Next oCOM
    17.    
    18.     Set oCOMSet = Nothing
    19.     Set oWMIService = Nothing
    20.     End
    21. End Sub

    Output:
    Code:
    Caption         : X3Button.ucX3Button
    ComponentId     : {86D8BF0F-163D-459F-A897-6BBA1870D3B9}
    Control         : True
    Description     : X3Button.ucX3Button
    InprocServer32  : D:\Programming\X3 Button\X3Button.ocx
    Insertable      : False
    JavaClass       : False
    ProgId          : X3Button.ucX3Button
    ToolBoxBitmap32 : D:\Programming\X3 Button\X3Button.ocx, 30000
    TypeLibraryId   : {E4BFA0E6-5F95-4C5C-AD49-FADB2AFCD5C6}
    Version         : 17.0
    Last edited by Xiphias3; Sep 17th, 2009 at 02:53 PM.

  15. #15

    Thread Starter
    Lively Member okosv's Avatar
    Join Date
    Sep 2006
    Posts
    95

    Re: [RESOLVED] Refer to spefic dll

    thanks, there is some another way to detect file of ActiveX control:
    Code:
    Const HKEY_CLASSES_ROOT=&H80000000
    Dim strValue
    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    oReg.GetExpandedStringValue HKEY_CLASSES_ROOT,"ActiveLock3.Globals\CLSID", "", strValue
    oReg.GetExpandedStringValue HKEY_CLASSES_ROOT,"CLSID\{4910BEE2-6F80-406B-B80F-3715B327C5F1}\InProcServer32", "", strValue
    WScript.Echo strValue

  16. #16
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: [RESOLVED] Refer to spefic dll

    Detecting is easy. In the app, theres the function:
    Code:
    isOLEServerRegistered

  17. #17

    Thread Starter
    Lively Member okosv's Avatar
    Join Date
    Sep 2006
    Posts
    95

    Re: [RESOLVED] Refer to spefic dll

    How can I use it?
    Thanks

Posting Permissions

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



Click Here to Expand Forum to Full Width