logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 Who's your daddy!

Posted on
2/21/2002
Author:
Robert Gelb
Email:
Not Shown
Applies To OS:
NT, 9x, 2000
Product:
5, 6



Every now and then you need to find the name of the EXE that loaded you DLL component. The reasons for needing this information are diverse. For instance, I have a component that's used by both desktop and server-side web application. When I run a desktop application, I want to return text separated by vbCrLf. However, to HTML code vbCrLf means nothing. Web-application would prefer the text to be separated by <br>. I need to know where the component is running so that its output matches that of its container.

Thus the need for a procedure that returns the name of the EXE (or another DLL) that loaded the DLL component. I wish I could take credit for this code, but I can't. I posted the question on the newsgroups ages ago and some good soul answered. So here is the anonymous code. In your code simply call WhosYourDaddy function.

Add the following code to form, module or class
Option Explicit

'API Declarations
Private Declare Function GetModuleFileName Lib _
    "kernel32" Alias "GetModuleFileNameA" (ByVal _
    hModule As Long, ByVal lpFileName As String, _
    ByVal nSize As Long) As Long

Private Function WhosYourDaddy() As String
    Dim AppPath As String
    Const MAX_PATH = 260
    
    On Error Resume Next

    'allocate space for the string
    AppPath = Space$(MAX_PATH)
    
    If GetModuleFileName(0, AppPath, Len(AppPath)) Then
        'Remove NULLs from the result
        AppPath = Left$(AppPath, InStr(AppPath, vbNullChar) - 1)
        WhosYourDaddy = AppPath
    Else
        WhosYourDaddy = "Not Found"
    End If
End Function
End Code



Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word:
 



Comments
#1. By mousabasiratnia. Posted on 5/9/2007 4:43:13 PM
hi
im an irania man that i wrote a programme like nero but a area of this programme faced problem . my problem is this that i cant write a function in vb.
this function is very very hard for me.
i wanna a function that write information in cd
and erase cd after writing
just this 2 function
for this reqest i will spend every mony that u want of me
iranian cant write this function
and i refer to you.
note : this function must writed in vb _ visual basic
thanks alot
my name is mousa basiratnia
my id : 3112284