CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2022

    return dll if its exists

    Hello, i'm trying to detect a "test.dll"(the name is just example) if it exists, and then to do my things in the code.The problem is, that whatever i do, "getmodulehandle" it always returns value null. I saw that, if the "test.dll" is detected, returns Windows Handle. I was searching on google for a solution but I couldn't find it. How to comparing the value if the example dll is found or if it's not? I'm sure there is something wrong in my example, but i cant understand what exactly. Can someone give me advice, how can i solve this? I'm pasting example code.

    Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long

    Sub main()
    If GetModuleHandle("test.dll") = true Then
    Exit Sub
    Do other things
    End if
    End sub

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: return dll if its exists

    Before "searching on google for a solution" you must first read the documentation about the Win32 function you 'll be going to use:
    It is very clear that GetModuleHandle returns not a Boolean value but HMODULE!
    Return value
    If the function succeeds, the return value is a handle to the specified module.

    If the function fails, the return value is NULL. To get extended error information, call GetLastError.
    Victor Nijegorodov

Tags for this Thread

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