Results 1 to 29 of 29

Thread: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Private Sub Command1_Click()
    On Error Resume Next
    Dim BC As olelib.IBindCtx
    Dim i As Integer
    Dim theROT As olelib.IRunningObjectTable
    Dim EMoniker As olelib.IEnumMoniker
    Dim Moniker As olelib.IMoniker
    CreateBindCtx 0, BC
    Set theROT = BC.GetRunningObjectTable
    Set EMoniker = theROT.EnumRunning
    Do While EMoniker.Next(1, Moniker, 0) = 0
    Set a = theROT.GetObject(Moniker)
    Debug.Print TypeName(a)
    ' If Right(a.Name, 3) = "xls" Or Right(a.Name, 4) = "xlsx" Then
    ' ReDim Preserve b(i)
    ' Set b(i) = a
    Me.List1.AddItem a.Name & " " & TypeName(a)
    If a.Name = "MyRot" Then MsgBox a.v
    ' i = i + 1
    ' End If
    Loop
    End Sub
    Last edited by xiaoyao; Feb 7th, 2020 at 01:00 PM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: how to vb6 getobject(**) by rot,List Rot ,GetRunningObjectTable

    1 ,how to call getobject("**") for running standard exe (not activex.exe)?
    2 , how to list all running rot ,get all guid like "{4E66DD81-18D8-4F97-A955-8589476621FD}"

    standard exe have no "GUID",NO ClsID,NO PROGID.
    it can call by GetRunningObjectTable,list all rot object:
    If a.Name = "MyRot" Then MsgBox a.v
    if getguid(a)="{4E66DD81-18D8-4F97-A955-8589476621FD}" then ***
    3,then we can get the object,how to createobject(**) to load a new object like this?
    '=============
    THe activex.dll have "PROGID",but the application (*.exe) does not have this property
    ==============
    CONST AFX_PROGID_ABC_Class1 = "ABC.Class1"

    ' // ClsIDs (类标识符)
    CONST AFX_CLSID_Class1 = "{755F2A6F-56B1-4C13-BBF6-1899148108B9}"

    ' // IIDs (接口标识符)
    CONST AFX_IID__Class1 = "{47B17DD5-2098-4DBF-8AB1-F162391F7DD1}"
    ================
    rot can add for vb6 (activex.exe),or activex.dll
    i found a way to add rot in standard exe.
    make exe by vb6,add new Class1,and put addrot code:

    'Visual Basic/VB, ROT
    'http://computer-programming-forum.com/72-visual-basic-vb/1146741ba0e3a67b.htm

    Code:
    Friend Sub AddToROT() 
      Dim LRet As Long 
      Dim TGUID As GUID1 
    ' "{4E66DD81-18D8-4F97-A955-8589476621FD}" 
    On Error Resume Next 
    With TGUID 
       .Data1 = &H4E66DD81 
       .Data2 = &H18D8 
       .Data3 = &H4F97 
       .Data4(0) = &HA9 
       .Data4(1) = &H55 
       .Data4(2) = &H85 
       .Data4(3) = &H89 
       .Data4(4) = &H47 
       .Data4(5) = &H66 
       .Data4(6) = &H21 
       .Data4(7) = &HFD 
    End With 
        LRet = RegisterActiveObject(ObjPtr(Me), VarPtr(TGUID), 
    ACTIVEOBJECT_STRONG, OLEInstance) 
    End Sub 
    Friend Sub RemoveFromROT() 
     On Error Resume Next 
      If OLEInstance <> 0 Then RevokeActiveObject OLEInstance, 0 
      CoDisconnectObject ObjPtr(Me), 0 
    End Sub

  3. #3
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: how to vb6 getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by xiaoyao View Post
    Private Sub Command1_Click()
    On Error Resume Next
    Dim BC As olelib.IBindCtx
    Dim i As Integer
    Dim theROT As olelib.IRunningObjectTable
    Dim EMoniker As olelib.IEnumMoniker
    Dim Moniker As olelib.IMoniker
    CreateBindCtx 0, BC
    Set theROT = BC.GetRunningObjectTable
    Set EMoniker = theROT.EnumRunning
    Do While EMoniker.Next(1, Moniker, 0) = 0
    Set a = theROT.GetObject(Moniker)
    Debug.Print TypeName(a)
    ' If Right(a.Name, 3) = "xls" Or Right(a.Name, 4) = "xlsx" Then
    ' ReDim Preserve b(i)
    ' Set b(i) = a
    Me.List1.AddItem a.Name & " " & TypeName(a)
    If a.Name = "MyRot" Then MsgBox a.v
    ' i = i + 1
    ' End If
    Loop
    End Sub
    Dear xiaoyao,

    You go thru http://www.vbforums.com/showthread.p...ating-the-ROT-! post #9

    regards,
    JSVenu

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,442

    Re: how to vb6 getobject(**) by rot,List Rot ,GetRunningObjectTable

    http://www.vbforums.com/showthread.php?879529

    Take a look at PutObject function. It uses file monikers and along with the built-in GetObject one can do the trick for Std-EXEs. No extra typelib needed too.

    cheers,
    </wqw>

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: how to vb6 getobject(**) by rot,List Rot ,GetRunningObjectTable

    very good, thank you very much
    Last edited by xiaoyao; Feb 6th, 2020 at 11:18 PM.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: how to vb6 getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by wqweto View Post
    http://www.vbforums.com/showthread.php?879529

    Take a look at PutObject function. It uses file monikers and along with the built-in GetObject one can do the trick for Std-EXEs. No extra typelib needed too.

    cheers,
    </wqw>
    I make a rot with virtual guid in Std-EXEs(abc.exe) ,then call by b.exe(use list all rot to find abc.exe by guid),So amazing and very convenient.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: how to vb6 getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by wqweto View Post
    http://www.vbforums.com/showthread.php?879529

    Take a look at PutObject function. It uses file monikers and along with the built-in GetObject one can do the trick for Std-EXEs. No extra typelib needed too.

    cheers,
    </wqw>
    maybe it's a new way,thank you.
    I want to study how to read memory address from 2 Std-EXEs.
    by getobject,by rot, maybe slowly.
    I test copymemory is quickly。
    use api "CreateFileMapping" ,share memory area by name like "memory_abc",read it from other process。
    To share data between processes, you need to open this "shared file name" and then use copymemory (RtlMoveMemory) to write or read data.
    Is there such a method, the second process creates a variable, such as: dim str2 as string, or dim strArr () as string, and then directly access the memory data using the variable name, without RtlMoveMemory faster
    chinese:进程之间共享数据需要打开这个"共享文件的名称",再用copymemory(RtlMoveMemory)写入或者读取数据。
    有没有这样一种方法,第二个进程创建一个变量,比如:dim str2 as string,或者 dim strArr() as string,然后直接用变量名进行访问内存数据,不用RtlMoveMemory速度更快

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    very good,PutObject
    Code:
    Option Explicit
     
    Private Declare Function GetRunningObjectTable Lib "ole32" (ByVal dwReserved As Long, pResult As IUnknown) As Long
    Private Declare Function CreateFileMoniker Lib "ole32" (ByVal lpszPathName As Long, pResult As IUnknown) As Long
    Private Declare Function DispCallFunc Lib "oleaut32" (ByVal pvInstance As Long, ByVal oVft As Long, ByVal lCc As Long, ByVal vtReturn As VbVarType, ByVal cActuals As Long, prgVt As Any, prgpVarg As Any, pvargResult As Variant) As Long
     
    Private m_lCookie As Long
     
    Private Sub Form_Load()
        List1.AddItem "test"
        List1.AddItem Now
        m_lCookie = PutObject(Me, "MySpecialProject.Form1")
    End Sub
     
    Private Sub Form_Unload(Cancel As Integer)
        RevokeObject m_lCookie
    End Sub
     
    Public Function PutObject(oObj As Object, sPathName As String, Optional ByVal Flags As Long) As Long
        Const ROTFLAGS_REGISTRATIONKEEPSALIVE As Long = 1
        Const IDX_REGISTER  As Long = 3
        Dim hResult         As Long
        Dim pROT            As IUnknown
        Dim pMoniker        As IUnknown
        
        hResult = GetRunningObjectTable(0, pROT)
        If hResult < 0 Then
            Err.Raise hResult, "GetRunningObjectTable"
        End If
        hResult = CreateFileMoniker(StrPtr(sPathName), pMoniker)
        If hResult < 0 Then
            Err.Raise hResult, "CreateFileMoniker"
        End If
        DispCallByVtbl pROT, IDX_REGISTER, ROTFLAGS_REGISTRATIONKEEPSALIVE Or Flags, ObjPtr(oObj), ObjPtr(pMoniker), VarPtr(PutObject)
    End Function
     
    Public Sub RevokeObject(ByVal lCookie As Long)
        Const IDX_REVOKE    As Long = 4
        Dim hResult         As Long
        Dim pROT            As IUnknown
        
        hResult = GetRunningObjectTable(0, pROT)
        If hResult < 0 Then
            Err.Raise hResult, "GetRunningObjectTable"
        End If
        DispCallByVtbl pROT, IDX_REVOKE, lCookie
    End Sub
     
    Private Function DispCallByVtbl(pUnk As IUnknown, ByVal lIndex As Long, ParamArray A() As Variant) As Variant
        Const CC_STDCALL    As Long = 4
        Dim lIdx            As Long
        Dim vParam()        As Variant
        Dim vType(0 To 63)  As Integer
        Dim vPtr(0 To 63)   As Long
        Dim hResult         As Long
        
        vParam = A
        For lIdx = 0 To UBound(vParam)
            vType(lIdx) = VarType(vParam(lIdx))
            vPtr(lIdx) = VarPtr(vParam(lIdx))
        Next
        hResult = DispCallFunc(ObjPtr(pUnk), lIndex * 4, CC_STDCALL, vbLong, lIdx, vType(0), vPtr(0), DispCallByVtbl)
        If hResult < 0 Then
            Err.Raise hResult, "DispCallFunc"
        End If
    End Function

  9. #9
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,442

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    FYI, here is one more function in this family on file monikers handlers -- IsObjectRunning function can check if a file moniker is registered w/o failing GetObject call for all those running VB6 IDE in "Break on All errors" mode (as every breaveheart professional should:-)).

    cheers,
    </wqw>

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by wqweto View Post
    FYI, here is one more function in this family on file monikers handlers -- IsObjectRunning function can check if a file moniker is registered w/o failing GetObject call for all those running VB6 IDE in "Break on All errors" mode (as every breaveheart professional should:-)).

    cheers,
    </wqw>
    thank you,do you known how to get the process id from rot object?
    or how to get process id from object(objptr)?

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Dim invDoc As dynamic = ComObject
    If New IntPtr(invDoc.Parent.MainFrameHWND) = hwnd Then
    https://social.msdn.microsoft.com/Fo...s-class-object
    Code:
    Variable für COM-Objekt
                        object comInstance;
                        Application qvApp;
                        // COM-Objekt über den Anzeigenamen abrfragen
                        runningObjectTable.GetObject(monikerContainer[0], out comInstance);
    
                        if (comInstance is Application)
                        {
                            qvApp = (Application)comInstance;
                            int pid = qvApp.GetProcessId();
                            if (pid == id)
                            {
                                return qvApp;
                            }
    
                        }
    https://stackoverflow.com/questions/...ial-process-id
    https://www.experts-exchange.com/que...rocess-ID.html
    Get application object from process ID.

    Enumerating the ROT in VB using APIs Help please !!
    https://www.experts-exchange.com/que...lp-please.html

    how to get processid by vb6?
    Last edited by xiaoyao; Feb 7th, 2020 at 07:42 PM.

  12. #12
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,759

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    xiaoyao,
    If you want to just communicate 2 or more executables you can use ObjRef moniker. It requires no administrative rights etc. You can get then reference to other hosts like vbs/vba/32/64 read the memory etc.
    But if you just want to read/write arbitrary memory you can use ReadProcessMemory/WriteProcessMemory apis. If you need to have a shared memory you could use FileMapping object (CreateFileMapping/MapViewOfFile). Alternatively you can create a DLL with a shared section.

  13. #13
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,442

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by xiaoyao View Post
    how to get processid by vb6?
    In the sample code you link there is this line

    int pid = qvApp.GetProcessId();

    Note that GetProcessId is a *custom* method of the application object, not something built-in into how ROT is working. You can always expose process id as a custom property or method on the form you are registering in ROT like this

    Code:
    Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
    
    Property Get ProcessID() As String
        ProcessID = GetCurrentProcessId()
    End Property
    cheers,
    </wqw>

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by The trick View Post
    xiaoyao,
    If you want to just communicate 2 or more executables you can use ObjRef moniker. It requires no administrative rights etc. You can get then reference to other hosts like vbs/vba/32/64 read the memory etc.
    But if you just want to read/write arbitrary memory you can use ReadProcessMemory/WriteProcessMemory apis. If you need to have a shared memory you could use FileMapping object (CreateFileMapping/MapViewOfFile). Alternatively you can create a DLL with a shared section.
    can you make a sample for "ObjRef moniker",thank you

  15. #15

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Can sPathName value be any string or repeated?

    Private Declare Function CreateFileMoniker Lib "ole32" (ByVal lpszPathName As Long, pResult As IUnknown) As Long

    what about lpszPathName??
    exe path like "c:\1.exe"?

    Code:
        Set Form2b = New Form2
        Form2b.Show
        m_lCookie = PutObject(Form2b)
    
    Public Function PutObject(oObj As Object, Optional ByVal Flags As Long, Optional ByVal sPathName As String) As Long
        If sPathName = "" Then sPathName = "objptr_" & ObjPtr(oObj)
        Const ROTFLAGS_REGISTRATIONKEEPSALIVE As Long = 1
        Const IDX_REGISTER  As Long = 3
        Dim hResult         As Long
        Dim pROT            As IUnknown
        Dim pMoniker        As IUnknown
        
        hResult = GetRunningObjectTable(0, pROT)
        If hResult < 0 Then
            Err.Raise hResult, "GetRunningObjectTable"
        End If
        hResult = CreateFileMoniker(StrPtr(sPathName), pMoniker)
        If hResult < 0 Then
            Err.Raise hResult, "CreateFileMoniker"
        End If
        DispCallByVtbl pROT, IDX_REGISTER, ROTFLAGS_REGISTRATIONKEEPSALIVE Or Flags, ObjPtr(oObj), ObjPtr(pMoniker), VarPtr(PutObject)
    End Function

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    CAN'T PUTobject?
    dim class5 as new class1

  18. #18
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,442

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by xiaoyao View Post
    CAN'T PUTobject?
    dim class5 as new class1
    For private classes you have to perform a one-time tweak of ObjectInfo flags to allow remote (public) access like done in this code by dz32.

    Possible but I wouldn't bother and just use forms.

    cheers,
    </wqw>

  19. #19

  20. #20

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    The rot process operates so that if the main program gets stuck, those clients will be prompted. The main program code and other conditions will cause the two processes to stutter.Maybe this is an old technology, and there are still many problems.

  21. #21
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,442

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    When using type-library-driven standard COM marshaling for inter-thread or inter-process communication (always the case with VB6 implemented COM classes) it's a good idea to set

    App.OleRequestPendingTimeout = 2 ^ 31 - 1

    . . . so that "waiting for call to complete" dialogs are minimized.

    cheers,
    </wqw>

  22. #22
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,019

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by The trick View Post
    See this function. By default the marshaling of private interfaces is disabled.
    This registry key is great, now private classes can be successfully registered in the ROT, but their events are still not being marshaled. Only events of registered ActiveX DLL classes are marshaled correctly...

  23. #23

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by VanGoghGaming View Post
    This registry key is great, now private classes can be successfully registered in the ROT, but their events are still not being marshaled. Only events of registered ActiveX DLL classes are marshaled correctly...
    you want to fire events on rot object like activex.exe?
    EVENTS FOR excel.workbook.open?

  24. #24

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by wqweto View Post
    For private classes you have to perform a one-time tweak of ObjectInfo flags to allow remote (public) access like done in this code by dz32.

    Possible but I wouldn't bother and just use forms.

    cheers,
    </wqw>
    class only used 7 vtable items,vb6 forms used 400 vtable items,so class object is best.
    i don't khnow if i use latebind events method to rot object ,can use like WIthevents ?

  25. #25
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,019

    Talking Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by xiaoyao View Post
    i don't know if i use latebind events method to rot object ,can use like WithEvents ?
    I've already tried late-bound events on ROT objects, it doesn't work (error: "Class does not support Automation or does not support expected interface"). It works only for ActiveX DLL objects that are placed in ROT and even then the DLL needs to be registered. If you try it "RegFree" then you get the same "Class does not support Automation" error.

    It looks like these late-bound events work only "in-process". There seems to be some marshaling issue when you try them "out-of-process".

  26. #26

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by VanGoghGaming View Post
    I've already tried late-bound events on ROT objects, it doesn't work (error: "Class does not support Automation or does not support expected interface"). It works only for ActiveX DLL objects that are placed in ROT and even then the DLL needs to be registered. If you try it "RegFree" then you get the same "Class does not support Automation" error.

    It looks like these late-bound events work only "in-process". There seems to be some marshaling issue when you try them "out-of-process".

    ROT OBJECT MAYBE like rpc,can't support events,maybe need microsoft corp to fixed by rot 2.0

  27. #27
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,019

    Talking Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    ROT objects support events just fine if their IIDs are found in the registry (like from registered ActiveX DLLs or EXEs). Obviously a form or private class can't be registered so it doesn't support events out-of-process. Or maybe their events need custom marshalling but I wouldn't know where to begin there.

  28. #28

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,297

    Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Quote Originally Posted by VanGoghGaming View Post
    ROT objects support events just fine if their IIDs are found in the registry (like from registered ActiveX DLLs or EXEs). Obviously a form or private class can't be registered so it doesn't support events out-of-process. Or maybe their events need custom marshalling but I wouldn't know where to begin there.
    maybe it support free reg dll?
    a.exe+DLL1.DLL by free reg dll,put DLL1.CLASS1 TO ROT OBJECT LIST

    B.EXE GETOBJECT WITH EVENTS BY Free reg dll?

  29. #29
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,019

    Talking Re: vb6 how to getobject(**) by rot,List Rot ,GetRunningObjectTable

    Yeah, the DLL can be loaded RegFree but events from a ROT object work only if the DLL is also registered even if it was loaded RegFree. The event interface needs to be marshaled between the two processes and the automatic marshaler works only if the DLL is registered. If you try it on another computer where the DLL is not registered then you will get an error saying "Class does not support automation or does not support expected interface".

    In fact I've already said all of this above but it's worth reiterating. It may work with a SxS manifest that includes a "Stub" element with the IID of the event interface but I haven't looked into that yet. I know wqweto has a manifest tool that may help in this regard: https://github.com/wqweto/UMMM, maybe you could take a look at it and see if it works with events for RegFree DLLs when they are placed into ROT.

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