Declarations...
Code
Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long

Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long




Code
Public Function GetModuleFileSpec(ModuleName As String) As String
'Purpose
'   Used to get the filespec of a loaded module (DLL or EXE).
'Parameters
'   ModuleName (String) = The name of the module to work with.
'Return (String)
'   Returns the filespec of the specified module.
'   If the specified module is not loaded (or does not exist), function returns a zero-length string.
'   If the specified module is a zero-length string, function returns the name of the hosting module,
'       aka. the current executable.
'Dependencies
'   The following API functions must be declared in the current project:
'       GetModuleHandle
'       GetModuleFileName
'Notes
'   The specified ModuleName can be resemble any of the following examples:
'       "rtStatus", "rtStatus.dll"
'   Also, concerning the ModuleName parameter, it seems that capitalization does not matter.
'Version History
'   1.0 4/6/2004 Tested by Russ Tanner
'       Tested on Windows 2000, Windows 95.
'---

'Constants
Const MAX_PATH = 260

'Initiate variables
Dim X As String 'General buffer
Dim R As Long 'API return value
Dim hModule As Long 'Handle to a module

'Get a handle to the specified module
hModule = GetModuleHandle(ModuleName)

'Error Trap: The specified module handle could not be attained, return error condition and exit now
If hModule = 0 Then
    GetModuleFileSpec = ""
    Exit Function
End If

'Get the filespec of the module
X = String(MAX_PATH + 1, 0) 'Prepare a string buffer
R = GetModuleFileName(hModule, X, MAX_PATH) 'Get the filespec of the module
GetModuleFileSpec = Left(X, R) 'Parse and return the filespec of the module

End Function


The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)