I am an .OCX: Who called me 
Author Message
 I am an .OCX: Who called me

Inside an OCX,
I would like to know the name of the program who called me.

I need the full path+name
Maybe in the future I will need the hWnd and process_ID

I mean: RETRIEVING them inside the OCX, without those informations
passed as a parameter

Thanks



Sat, 28 Jul 2001 03:00:00 GMT  
 I am an .OCX: Who called me
Download my control called ProcessesInfo from my web site. As it's made with
VB5CCE you can do it with VB, but because you posted this message so many
times and you are "Mr. Anonymous" (no name and no valid email) I will not
post the code for you.

--
Eduardo Morcillo

http://www.geocities.com/SiliconValley/Foothills/9940/index_sp.html



Sat, 28 Jul 2001 03:00:00 GMT  
 I am an .OCX: Who called me

|Download my control called ProcessesInfo from my web site. As it's made with
|VB5CCE you can do it with VB, but because you posted this message so many
|times and you are "Mr. Anonymous" (no name and no valid email) I will not
|post the code for you.

============================
Two questions:
 How many copies of my post did you see ?
     (multipost I mean: I know I crossposted 3 NG)
      Because I started posting Saturday, and then once a day
      My post did not appear before Tuesday (GMT), with your answer
      So far, there is ONE copy on my server
 Which is your newserver ?
  If you see more than one copy, your newsserver is better than mine
  I use msnews.microsoft.com: nothing is supposed to be better.
  So: enlighten me, as that feed problem has beeen lasting 2 weeks now
==============================
About the question I answered, I managed to do something that works.
I alm not sure it is the shortest way:
  App.hWnd:   get the hwnd of the OCX
  GetWindowThreadProcessId: get the Process-ID of the .OCX
  Process32First + Process32Next until I find a th32ProcessID = my process-ID
    Here is my Dad
Is there something shorter ???


PS: I a going to have a look at your code
==================================================================================
==================================================================================
Attribute VB_Name = "Module_WhoIsMyDad"
Option Explicit
'############################################################################################
        Private Const MAX_MODULE_NAME32 As Integer = 255
        Private Const MAX_MODULE_NAME32plus As Integer = MAX_MODULE_NAME32 + 1
        Private Const MAX_PATH = 260
        Public Const TH32CS_SNAPPROCESS = &H2&
        Public Const TH32CS_SNAPMODULE = &H8&
        Public Const hNull = 0
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Type PROCESSENTRY32
    dwSize               As Long 'Specifies the length, in bytes, of the structure.
    cntUsage             As Long 'Number of references to the process.
    th32ProcessID        As Long 'Identifier of the process.
    th32DefaultHeapID    As Long 'Identifier of the default heap for the process.
    th32ModuleID         As Long 'Module identifier of the process. (Associated exe)
    cntThreads           As Long 'Number of execution threads started by the process.
    th32ParentProcessID  As Long 'Identifier of the process that created the process being examined.
    pcPriClassBase       As Long 'Base priority of any threads created by this process.
    dwFlags              As Long 'Reserved; do not use.
    szExeFile            As String * MAX_PATH 'Path and filename of the executable file for the process.
End Type
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Type MODULEENTRY32
    dwSize          As Long 'Specifies the length, in bytes, of the structure.
    th32ModuleID    As Long 'Module identifier in the context of the owning process.
    th32ProcessID   As Long 'Identifier of the process being examined.
    GlblcntUsage    As Long 'Global usage count on the module.
    ProccntUsage    As Long 'Module usage count in the context of the owning process.
    modBaseAddr     As Long 'Base address of the module in the context of the owning process.
    modBaseSize     As Long 'Size, in bytes, of the module.
    hModule         As Long 'Handle to the module in the context of the owning process.
    szModule        As String * MAX_MODULE_NAME32plus 'String containing the module name.
    szExePath       As String * MAX_PATH 'String containing the location (path) of the module.
End Type
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Declare Function GetWindowThreadProcessId Lib "user32" _
       (ByVal hWnd As Long, _
        lpdwProcessID As Long) _
        As Long
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" _
       (ByVal dwFlags As Long, _
        ByVal th32ProcessID As Long) _
        As Long
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Declare Function Process32First Lib "kernel32" _
       (ByVal hSnapshot As Long, _
        lppe As PROCESSENTRY32) _
        As Long
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Declare Function Process32Next Lib "kernel32" _
        (ByVal hSnapshot As Long, _
         lppe As PROCESSENTRY32) _
         As Long
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Declare Function Module32First Lib "kernel32" _
       (ByVal hSnapshot As Long, _
        lpme As MODULEENTRY32) _
        As Long
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Declare Function Module32Next Lib "kernel32" _
       (ByVal hSnapshot As Long, _
        lpme As MODULEENTRY32) _
        As Long
 '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Declare Function CloseHandle Lib "Kernel32.dll" _
       (ByVal Handle As Long) _
        As Long
'############################################################################################
Private Function RTrimNull(s As String) As String
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    RTrimNull = Left$(s, InStr(s, vbNullChar) - 1)
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
End Function
'############################################################################################
Public Function Dad(ByRef frm As Form) As String
    Dim hProcessId As Long
    Dim lReturnID       As Long
    Dim hSnapProcess    As Long
    Dim proc            As PROCESSENTRY32
    Dim module          As MODULEENTRY32
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    GetWindowThreadProcessId frm.hWnd, hProcessId
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    hSnapProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If hSnapProcess = hNull Then
        Dad = ""
    Else
        proc.dwSize = Len(proc)
        lReturnID = Process32First(hSnapProcess, proc)
        Do While lReturnID <> 0
            If (proc.th32ProcessID = hProcessId) Then
                Dad = RTrimNull(proc.szExeFile)
                Exit Do
            Else
                lReturnID = Process32Next(hSnapProcess, proc)
            End If
        Loop
        CloseHandle hSnapProcess
    End If
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
End Function
'############################################################################################
==================================================================================
==================================================================================



Sun, 29 Jul 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. I am an .OCX: Who called me ?

2. I am an .OCX: Who called me

3. I am an .OCX: Who called me ?

4. OCX OCX OCX OCX OCX OCX

5. Using MSMAPI ocx: Am I stupid or what?

6. I am tired of COMCTL32.OCX

7. I am tired of COMCTL32.OCX

8. Help with API Calls please.........I am at wits end :(

9. Calling A Function (What am I doing wrong)

10. Call Function of am Modul = Error !

11. What am I missing in the API call?

12. BAD DLL calling conventions - What am I doing wrong

 

 
Powered by phpBB® Forum Software