Results 1 to 29 of 29

Thread: [VB6] - Module for working with COM-Dll without registration.

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,671

    [VB6] - Module for working with COM-Dll without registration.

    Hello. I give my module for working with COM-DLL without registration in the registry.
    The module has several functions:
    1. GetAllCoclasses - returns to the list of classes and unique identifiers are extracted from a type library.
    2. CreateIDispatch - creates IDispatch implementation by reference to the object and the name of the interface.
    3. CreateObjectEx2 - creates an object by name from a type library.
    4. CreateObjectEx - creates an object by CLSID.
    5. UnloadLibrary - unloads the DLL if it is not used.

    vb Code:
    1. ' The module modTrickUnregCOM.bas - for working with COM libraries without registration.
    2. ' © Krivous Anatolii Anatolevich (The trick), 2015
    3.  
    4. Option Explicit
    5.  
    6. . . .
    7. D E C L A R A T I O N
    8. . . .
    9.  
    10. Dim iidClsFctr      As GUID
    11. Dim iidUnk          As GUID
    12. Dim isInit          As Boolean
    13.  
    14. ' // Get all co-classes described in type library.
    15. Public Function GetAllCoclasses( _
    16.                 ByRef path As String, _
    17.                 ByRef listOfClsid() As GUID, _
    18.                 ByRef listOfNames() As String, _
    19.                 ByRef countCoClass As Long) As Boolean
    20.                
    21.     Dim typeLib As IUnknown
    22.     Dim typeInf As IUnknown
    23.     Dim ret     As Long
    24.     Dim count   As Long
    25.     Dim index   As Long
    26.     Dim pAttr   As Long
    27.     Dim tKind   As Long
    28.    
    29.     ret = LoadTypeLibEx(StrPtr(path), REGKIND_NONE, typeLib)
    30.    
    31.     If ret Then
    32.         Err.Raise ret
    33.         Exit Function
    34.     End If
    35.    
    36.     count = ITypeLib_GetTypeInfoCount(typeLib)
    37.     countCoClass = 0
    38.    
    39.     If count > 0 Then
    40.    
    41.         ReDim listOfClsid(count - 1)
    42.         ReDim listOfNames(count - 1)
    43.        
    44.         For index = 0 To count - 1
    45.        
    46.             ret = ITypeLib_GetTypeInfo(typeLib, index, typeInf)
    47.                        
    48.             If ret Then
    49.                 Err.Raise ret
    50.                 Exit Function
    51.             End If
    52.            
    53.             ITypeInfo_GetTypeAttr typeInf, pAttr
    54.            
    55.             GetMem4 ByVal pAttr + &H28, tKind
    56.            
    57.             If tKind = TKIND_COCLASS Then
    58.            
    59.                 memcpy listOfClsid(countCoClass), ByVal pAttr, Len(listOfClsid(countCoClass))
    60.                 ret = ITypeInfo_GetDocumentation(typeInf, -1, listOfNames(countCoClass), vbNullString, 0, vbNullString)
    61.                
    62.                 If ret Then
    63.                     ITypeInfo_ReleaseTypeAttr typeInf, pAttr
    64.                     Err.Raise ret
    65.                     Exit Function
    66.                 End If
    67.                
    68.                 countCoClass = countCoClass + 1
    69.                
    70.             End If
    71.            
    72.             ITypeInfo_ReleaseTypeAttr typeInf, pAttr
    73.            
    74.             Set typeInf = Nothing
    75.            
    76.         Next
    77.        
    78.     End If
    79.    
    80.     If countCoClass Then
    81.        
    82.         ReDim Preserve listOfClsid(countCoClass - 1)
    83.         ReDim Preserve listOfNames(countCoClass - 1)
    84.    
    85.     Else
    86.    
    87.         Erase listOfClsid()
    88.         Erase listOfNames()
    89.        
    90.     End If
    91.    
    92.     GetAllCoclasses = True
    93.    
    94. End Function
    95.  
    96. ' // Create IDispach implementation described in type library.
    97. Public Function CreateIDispatch( _
    98.                 ByRef obj As IUnknown, _
    99.                 ByRef typeLibPath As String, _
    100.                 ByRef interfaceName As String) As Object
    101.                
    102.     Dim typeLib As IUnknown
    103.     Dim typeInf As IUnknown
    104.     Dim ret     As Long
    105.     Dim retObj  As IUnknown
    106.     Dim pAttr   As Long
    107.     Dim tKind   As Long
    108.    
    109.     ret = LoadTypeLibEx(StrPtr(typeLibPath), REGKIND_NONE, typeLib)
    110.    
    111.     If ret Then
    112.         Err.Raise ret
    113.         Exit Function
    114.     End If
    115.    
    116.     ret = ITypeLib_FindName(typeLib, interfaceName, 0, typeInf, 0, 1)
    117.    
    118.     If typeInf Is Nothing Then
    119.         Err.Raise &H80004002, , "Interface not found"
    120.         Exit Function
    121.     End If
    122.    
    123.     ITypeInfo_GetTypeAttr typeInf, pAttr
    124.     GetMem4 ByVal pAttr + &H28, tKind
    125.     ITypeInfo_ReleaseTypeAttr typeInf, pAttr
    126.    
    127.     If tKind = TKIND_DISPATCH Then
    128.         Set CreateIDispatch = obj
    129.         Exit Function
    130.     ElseIf tKind <> TKIND_INTERFACE Then
    131.         Err.Raise &H80004002, , "Interface not found"
    132.         Exit Function
    133.     End If
    134.  
    135.     ret = CreateStdDispatch(Nothing, obj, typeInf, retObj)
    136.    
    137.     If ret Then
    138.         Err.Raise ret
    139.         Exit Function
    140.     End If
    141.    
    142.     Set CreateIDispatch = retObj
    143.  
    144. End Function
    145.  
    146. ' // Create object by Name.
    147. Public Function CreateObjectEx2( _
    148.                 ByRef pathToDll As String, _
    149.                 ByRef pathToTLB As String, _
    150.                 ByRef className As String) As IUnknown
    151.                
    152.     Dim typeLib As IUnknown
    153.     Dim typeInf As IUnknown
    154.     Dim ret     As Long
    155.     Dim pAttr   As Long
    156.     Dim tKind   As Long
    157.     Dim clsid   As GUID
    158.    
    159.     ret = LoadTypeLibEx(StrPtr(pathToTLB), REGKIND_NONE, typeLib)
    160.    
    161.     If ret Then
    162.         Err.Raise ret
    163.         Exit Function
    164.     End If
    165.    
    166.     ret = ITypeLib_FindName(typeLib, className, 0, typeInf, 0, 1)
    167.    
    168.     If typeInf Is Nothing Then
    169.         Err.Raise &H80040111, , "Class not found in type library"
    170.         Exit Function
    171.     End If
    172.  
    173.     ITypeInfo_GetTypeAttr typeInf, pAttr
    174.    
    175.     GetMem4 ByVal pAttr + &H28, tKind
    176.    
    177.     If tKind = TKIND_COCLASS Then
    178.         memcpy clsid, ByVal pAttr, Len(clsid)
    179.     Else
    180.         Err.Raise &H80040111, , "Class not found in type library"
    181.         Exit Function
    182.     End If
    183.    
    184.     ITypeInfo_ReleaseTypeAttr typeInf, pAttr
    185.            
    186.     Set CreateObjectEx2 = CreateObjectEx(pathToDll, clsid)
    187.    
    188. End Function
    189.                
    190. ' // Create object by CLSID and path.
    191. Public Function CreateObjectEx( _
    192.                 ByRef path As String, _
    193.                 ByRef clsid As GUID) As IUnknown
    194.                
    195.     Dim hLib    As Long
    196.     Dim lpAddr  As Long
    197.     Dim isLoad  As Boolean
    198.    
    199.     hLib = GetModuleHandle(StrPtr(path))
    200.    
    201.     If hLib = 0 Then
    202.    
    203.         hLib = LoadLibrary(StrPtr(path))
    204.         If hLib = 0 Then
    205.             Err.Raise 53, , Error(53) & " " & Chr$(34) & path & Chr$(34)
    206.             Exit Function
    207.         End If
    208.        
    209.         isLoad = True
    210.        
    211.     End If
    212.    
    213.     lpAddr = GetProcAddress(hLib, "DllGetClassObject")
    214.    
    215.     If lpAddr = 0 Then
    216.         If isLoad Then FreeLibrary hLib
    217.         Err.Raise 453, , "Can't find dll entry point DllGetClasesObject in " & Chr$(34) & path & Chr$(34)
    218.         Exit Function
    219.     End If
    220.  
    221.     If Not isInit Then
    222.         CLSIDFromString StrPtr(IID_IClassFactory), iidClsFctr
    223.         CLSIDFromString StrPtr(IID_IUnknown), iidUnk
    224.         isInit = True
    225.     End If
    226.    
    227.     Dim ret     As Long
    228.     Dim out     As IUnknown
    229.    
    230.     ret = DllGetClassObject(lpAddr, clsid, iidClsFctr, out)
    231.    
    232.     If ret = 0 Then
    233.  
    234.         ret = IClassFactory_CreateInstance(out, 0, iidUnk, CreateObjectEx)
    235.    
    236.     Else
    237.    
    238.         If isLoad Then FreeLibrary hLib
    239.         Err.Raise ret
    240.         Exit Function
    241.        
    242.     End If
    243.    
    244.     Set out = Nothing
    245.    
    246.     If ret Then
    247.    
    248.         If isLoad Then FreeLibrary hLib
    249.         Err.Raise ret
    250.  
    251.     End If
    252.    
    253. End Function
    254.  
    255. ' // Unload DLL if not used.
    256. Public Function UnloadLibrary( _
    257.                 ByRef path As String) As Boolean
    258.                
    259.     Dim hLib    As Long
    260.     Dim lpAddr  As Long
    261.     Dim ret     As Long
    262.    
    263.     If Not isInit Then Exit Function
    264.    
    265.     hLib = GetModuleHandle(StrPtr(path))
    266.     If hLib = 0 Then Exit Function
    267.    
    268.     lpAddr = GetProcAddress(hLib, "DllCanUnloadNow")
    269.     If lpAddr = 0 Then Exit Function
    270.    
    271.     ret = DllCanUnloadNow(lpAddr)
    272.    
    273.     If ret = 0 Then
    274.         FreeLibrary hLib
    275.         UnloadLibrary = True
    276.     End If
    277.    
    278. End Function
    279.  
    280. ' // Call "DllGetClassObject" function using a pointer.
    281. Private Function DllGetClassObject( _
    282.                  ByVal funcAddr As Long, _
    283.                  ByRef clsid As GUID, _
    284.                  ByRef iid As GUID, _
    285.                  ByRef out As IUnknown) As Long
    286.                  
    287.     Dim params(2)   As Variant
    288.     Dim types(2)    As Integer
    289.     Dim list(2)     As Long
    290.     Dim resultCall  As Long
    291.     Dim pIndex      As Long
    292.     Dim pReturn     As Variant
    293.    
    294.     params(0) = VarPtr(clsid)
    295.     params(1) = VarPtr(iid)
    296.     params(2) = VarPtr(out)
    297.    
    298.     For pIndex = 0 To UBound(params)
    299.         list(pIndex) = VarPtr(params(pIndex)):   types(pIndex) = VarType(params(pIndex))
    300.     Next
    301.    
    302.     resultCall = DispCallFunc(0&, funcAddr, CC_STDCALL, vbLong, 3, types(0), list(0), pReturn)
    303.              
    304.     If resultCall Then Err.Raise 5: Exit Function
    305.    
    306.     DllGetClassObject = pReturn
    307.    
    308. End Function
    309.  
    310. ' // Call "DllCanUnloadNow" function using a pointer.
    311. Private Function DllCanUnloadNow( _
    312.                  ByVal funcAddr As Long) As Long
    313.                  
    314.     Dim resultCall  As Long
    315.     Dim pReturn     As Variant
    316.    
    317.     resultCall = DispCallFunc(0&, funcAddr, CC_STDCALL, vbLong, 0, ByVal 0&, ByVal 0&, pReturn)
    318.              
    319.     If resultCall Then Err.Raise 5: Exit Function
    320.    
    321.     DllCanUnloadNow = pReturn
    322.    
    323. End Function
    324.  
    325. ' // Call "IClassFactory:CreateInstance" method.
    326. Private Function IClassFactory_CreateInstance( _
    327.                  ByVal obj As IUnknown, _
    328.                  ByVal punkOuter As Long, _
    329.                  ByRef riid As GUID, _
    330.                  ByRef out As IUnknown) As Long
    331.    
    332.     Dim params(2)   As Variant
    333.     Dim types(2)    As Integer
    334.     Dim list(2)     As Long
    335.     Dim resultCall  As Long
    336.     Dim pIndex      As Long
    337.     Dim pReturn     As Variant
    338.    
    339.     params(0) = punkOuter
    340.     params(1) = VarPtr(riid)
    341.     params(2) = VarPtr(out)
    342.    
    343.     For pIndex = 0 To UBound(params)
    344.         list(pIndex) = VarPtr(params(pIndex)):   types(pIndex) = VarType(params(pIndex))
    345.     Next
    346.    
    347.     resultCall = DispCallFunc(obj, &HC, CC_STDCALL, vbLong, 3, types(0), list(0), pReturn)
    348.          
    349.     If resultCall Then Err.Raise resultCall: Exit Function
    350.      
    351.     IClassFactory_CreateInstance = pReturn
    352.    
    353. End Function
    354.  
    355. ' // Call "ITypeLib:GetTypeInfoCount" method.
    356. Private Function ITypeLib_GetTypeInfoCount( _
    357.                  ByVal obj As IUnknown) As Long
    358.    
    359.     Dim resultCall  As Long
    360.     Dim pReturn     As Variant
    361.  
    362.     resultCall = DispCallFunc(obj, &HC, CC_STDCALL, vbLong, 0, ByVal 0&, ByVal 0&, pReturn)
    363.          
    364.     If resultCall Then Err.Raise resultCall: Exit Function
    365.      
    366.     ITypeLib_GetTypeInfoCount = pReturn
    367.    
    368. End Function
    369.  
    370. ' // Call "ITypeLib:GetTypeInfo" method.
    371. Private Function ITypeLib_GetTypeInfo( _
    372.                  ByVal obj As IUnknown, _
    373.                  ByVal index As Long, _
    374.                  ByRef ppTInfo As IUnknown) As Long
    375.    
    376.     Dim params(1)   As Variant
    377.     Dim types(1)    As Integer
    378.     Dim list(1)     As Long
    379.     Dim resultCall  As Long
    380.     Dim pIndex      As Long
    381.     Dim pReturn     As Variant
    382.    
    383.     params(0) = index
    384.     params(1) = VarPtr(ppTInfo)
    385.    
    386.     For pIndex = 0 To UBound(params)
    387.         list(pIndex) = VarPtr(params(pIndex)):   types(pIndex) = VarType(params(pIndex))
    388.     Next
    389.    
    390.     resultCall = DispCallFunc(obj, &H10, CC_STDCALL, vbLong, 2, types(0), list(0), pReturn)
    391.          
    392.     If resultCall Then Err.Raise resultCall: Exit Function
    393.      
    394.     ITypeLib_GetTypeInfo = pReturn
    395.    
    396. End Function
    397.  
    398. ' // Call "ITypeLib:FindName" method.
    399. Private Function ITypeLib_FindName( _
    400.                  ByVal obj As IUnknown, _
    401.                  ByRef szNameBuf As String, _
    402.                  ByVal lHashVal As Long, _
    403.                  ByRef ppTInfo As IUnknown, _
    404.                  ByRef rgMemId As Long, _
    405.                  ByRef pcFound As Integer) As Long
    406.    
    407.     Dim params(4)   As Variant
    408.     Dim types(4)    As Integer
    409.     Dim list(4)     As Long
    410.     Dim resultCall  As Long
    411.     Dim pIndex      As Long
    412.     Dim pReturn     As Variant
    413.    
    414.     params(0) = StrPtr(szNameBuf)
    415.     params(1) = lHashVal
    416.     params(2) = VarPtr(ppTInfo)
    417.     params(3) = VarPtr(rgMemId)
    418.     params(4) = VarPtr(pcFound)
    419.    
    420.     For pIndex = 0 To UBound(params)
    421.         list(pIndex) = VarPtr(params(pIndex)):   types(pIndex) = VarType(params(pIndex))
    422.     Next
    423.    
    424.     resultCall = DispCallFunc(obj, &H2C, CC_STDCALL, vbLong, 5, types(0), list(0), pReturn)
    425.          
    426.     If resultCall Then Err.Raise resultCall: Exit Function
    427.      
    428.     ITypeLib_FindName = pReturn
    429.    
    430. End Function
    431.  
    432. ' // Call "ITypeInfo:GetTypeAttr" method.
    433. Private Sub ITypeInfo_GetTypeAttr( _
    434.             ByVal obj As IUnknown, _
    435.             ByRef ppTypeAttr As Long)
    436.    
    437.     Dim resultCall  As Long
    438.     Dim pReturn     As Variant
    439.    
    440.     pReturn = VarPtr(ppTypeAttr)
    441.    
    442.     resultCall = DispCallFunc(obj, &HC, CC_STDCALL, vbEmpty, 1, vbLong, VarPtr(pReturn), 0)
    443.          
    444.     If resultCall Then Err.Raise resultCall: Exit Sub
    445.  
    446. End Sub
    447.  
    448. ' // Call "ITypeInfo:GetDocumentation" method.
    449. Private Function ITypeInfo_GetDocumentation( _
    450.                  ByVal obj As IUnknown, _
    451.                  ByVal memid As Long, _
    452.                  ByRef pBstrName As String, _
    453.                  ByRef pBstrDocString As String, _
    454.                  ByRef pdwHelpContext As Long, _
    455.                  ByRef pBstrHelpFile As String) As Long
    456.    
    457.     Dim params(4)   As Variant
    458.     Dim types(4)    As Integer
    459.     Dim list(4)     As Long
    460.     Dim resultCall  As Long
    461.     Dim pIndex      As Long
    462.     Dim pReturn     As Variant
    463.    
    464.     params(0) = memid
    465.     params(1) = VarPtr(pBstrName)
    466.     params(2) = VarPtr(pBstrDocString)
    467.     params(3) = VarPtr(pdwHelpContext)
    468.     params(4) = VarPtr(pBstrHelpFile)
    469.    
    470.     For pIndex = 0 To UBound(params)
    471.         list(pIndex) = VarPtr(params(pIndex)):   types(pIndex) = VarType(params(pIndex))
    472.     Next
    473.    
    474.     resultCall = DispCallFunc(obj, &H30, CC_STDCALL, vbLong, 5, types(0), list(0), pReturn)
    475.          
    476.     If resultCall Then Err.Raise resultCall: Exit Function
    477.      
    478.     ITypeInfo_GetDocumentation = pReturn
    479.    
    480. End Function
    481.  
    482. ' // Call "ITypeInfo:ReleaseTypeAttr" method.
    483. Private Sub ITypeInfo_ReleaseTypeAttr( _
    484.             ByVal obj As IUnknown, _
    485.             ByVal ppTypeAttr As Long)
    486.    
    487.     Dim resultCall  As Long
    488.    
    489.     resultCall = DispCallFunc(obj, &H4C, CC_STDCALL, vbEmpty, 1, vbLong, VarPtr(CVar(ppTypeAttr)), 0)
    490.          
    491.     If resultCall Then Err.Raise resultCall: Exit Sub
    492.  
    493. End Sub

    Download.

  2. #2
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: [VB6] - Module for working with COM-Dll without registration.

    the download isn't working for me. What references are needed?
    And do you have any examples ?

  3. #3

  4. #4
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: [VB6] - Module for working with COM-Dll without registration.

    New project, paste your code into a new class file, and run...

    CC_STDCALL is not defined, etc. I'm assuming you have a reference to a type library or DLL

    In the VB6 IDE It's under Project-> References...
    Last edited by DEXWERX; Jul 10th, 2015 at 08:14 AM.

  5. #5

  6. #6
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: [VB6] - Module for working with COM-Dll without registration.

    That makes sense now. Corporate firewall doesn't like the link. Can someone attach it here?

    Go Advanced, and then Manage attachments.

  7. #7

  8. #8
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: [VB6] - Module for working with COM-Dll without registration.

    Thanks! This works without using ActCtx. Brilliant.

  9. #9
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: [VB6] - Module for working with COM-Dll without registration.

    I've modified dilettante's Regfee COM demo / Pine Plugins Form_Load()
    with the following lines

    Code:
            Set Plugins(Plugin) = CreateObjectEx2( _
                path & FileName & "dll", _
                path & FileName & "dll", _
                FileName & "PluginClass")
    Is there an easy way to generate the TLB file without installing VS/VC++?

    or do I need to use CreateObjectEx and use the CLSID out of the manifest?


    **UPDATE**
    This seemed to work well:

    Code:
            Set Plugins(Plugin) = CreateObjectEx2( _
                path & FileName & "dll", _
                path & FileName & "dll", _
                "PluginClass")

    Unless anyone can find any issues, this seems like a great way to load and use COM dll's REGFREE without manifests or TLBs etc. at least in this case.
    Last edited by DEXWERX; Jul 10th, 2015 at 01:28 PM.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,671

    Re: [VB6] - Module for working with COM-Dll without registration.

    Is there an easy way to generate the TLB file without installing VS/VC++?
    Usually tlb contained inside dll into resource, therefore you can pass same value for dll and tlb.
    or do I need to use CreateObjectEx and use the CLSID out of the manifest?
    If you know CLSID you can use just CreateObjectEx without tlb. For example zipfldr.dll (standart library for working with zip-files) don't contained tlb, therefore you can use CLSID for create com-objects from this DLL. If you can CLSID then it fastet than using of CreateObjectEx2.
    This module contained useful function CreateIDispatch, it allow create dynamicli interfaces from TLB. For example, if you want use a ITypeLib interface you can pass this name to CreateIDispatch function and path to tlb that contained a description of ITypeLib interface. This function return pointer to IDispatch interface and further you can call any ITypeLib methods use this IDispatch interface (or CallByName etc).

  11. #11
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Module for working with COM-Dll without registration.

    Hi, can i use this bas to get cls members for a dll.

  12. #12

  13. #13
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Module for working with COM-Dll without registration.

    Thank u, I wanna use Muti-Threading in vba-based environment, like ms-office word/Excel
    but there is no such demo. I have find some dlls used in vb6
    Here are some dll or codes for vb6, but i can't use them in vba
    Can Thread Factory used in vba? or is there any solution?
    Last edited by FunkyDexter; Apr 3rd, 2016 at 02:07 PM.

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,671

    Re: [VB6] - Module for working with COM-Dll without registration.

    Quote Originally Posted by loquat View Post
    Thank u, I wanna use Muti-Threading in vba-based environment, like ms-office word/Excel
    but there is no such demo. I have find some dlls used in vb6
    Here are some dll or codes for vb6, but i can't use them in vba

    Can Thread Factory used in vba? or is there any solution?
    I think you confuse the thread. This thread is not about multithreading.

  15. #15
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: [VB6] - Module for working with COM-Dll without registration.

    Loquat, I've removed your attachment because we have a rule against posting closed code (exes, zips etc.) on the forum. The only place it's acceptable is in the Utilities sub-forums and then only if the associated source is included. Please refrain from doing that in the future. Thanks.

    Regards
    FD
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  16. #16
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Module for working with COM-Dll without registration.

    >FD and The trick
    my English is not that good, and I have learn in this forum only yesterday.
    sorry to bother you.

  17. #17
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Module for working with COM-Dll without registration.

    i have used your UnRegCom module for long time, and have tested your unreg control project you publish in other website.
    and i have two questions.
    1.how can we get the event trigger of the object created by "CreateObjectEx"?
    2.many of the controls from 3rd party, can not be loaded by ControlsAdd Function, shows "need license" as such.
    can we make bypass of it?
    or how should i compile the usercontrol to be used in this situation?

  18. #18
    New Member
    Join Date
    May 2020
    Posts
    7

    Re: [VB6] - Module for working with COM-Dll without registration.

    System multiple Excel Application,only get the first 。
    how using process id get Excel Application object ?
    or
    Get a Collection of All Running Excel Instances?

  19. #19
    Member
    Join Date
    Apr 2019
    Posts
    63

    Re: [VB6] - Module for working with COM-Dll without registration.

    Quote Originally Posted by ln_0 View Post
    System multiple Excel Application,only get the first 。
    how using process id get Excel Application object ?
    or
    Get a Collection of All Running Excel Instances?
    Google is your friend, this is the wrong thread, but googling WM_GETOBJECT Excel, will help get you on the right track

  20. #20
    New Member
    Join Date
    May 2020
    Posts
    7

    Re: [VB6] - Module for working with COM-Dll without registration.

    Google = 404
    china.

  21. #21

    Thread Starter
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,671

    Re: [VB6] - Module for working with COM-Dll without registration.

    Quote Originally Posted by loquat View Post
    1.how can we get the event trigger of the object created by "CreateObjectEx"?
    WithEvents.

    Quote Originally Posted by loquat View Post
    2.many of the controls from 3rd party, can not be loaded by ControlsAdd Function, shows "need license" as such.
    can we make bypass of it?
    What you tell about?

    System multiple Excel Application,only get the first 。
    how using process id get Excel Application object ?
    or
    Get a Collection of All Running Excel Instances?
    This question isn't related to this thread. The answer is Running Object Table.

  22. #22
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,742

    Re: [VB6] - Module for working with COM-Dll without registration.

    rot can get all object,
    so you can get hwnd by object

  23. #23
    Banned
    Join Date
    May 2020
    Location
    https://t.me/pump_upp
    Posts
    42

    Re: [VB6] - Module for working with COM-Dll without registration.

    Another way is to use the following function... it seems to be similar to New_c.RegFree.GetInstanceEx in Olaf's vbRichClient5.dll
    Below is a part of its many association functions
    The following function was not written by me, but copied from unknown Internet by someone else

    Code:
    Public Function getInstance(ByVal LibraryString As String, ByVal ProgIdString As String) As stdole.IUnknown
        Dim newobj As stdole.IUnknown
        Dim TFactory As IClassFactory
        Dim classid As GUID
        Dim IID_ClassFactory As GUID
        Dim IID_IUnknown As GUID
        Dim lib As String
        Dim obj As Long
        Dim vtbl As Long
        Dim hModule As Long
        Dim pFunc As Long
        Dim arrTCoClass() As CoClass
        Dim i As Long, n As Long
        Dim flag As Boolean
        Dim strClassname As String
        n = InStr(1, ProgIdString, ".")
        If n > 0 Then
            strClassname = Mid(ProgIdString, n + 1)
            n = InStr(1, strClassname, ".")
            If n > 0 Then strClassname = Left(ProgIdString, n - 1)
        Else
            strClassname = ProgIdString
        End If
        With IID_ClassFactory
            .Data1 = &H1
            .Data4(0) = &HC0
            .Data4(7) = &H46
        End With
        With IID_IUnknown
            .Data4(0) = &HC0
            .Data4(7) = &H46
        End With
        ' get all CoClasses from the type lib of the file, and find the GUID of the Prog ID
        If Not getCoClasses(LibraryString, arrTCoClass) Then
            Exit Function
        End If
        For i = 0 To UBound(arrTCoClass)
            #If DEBUGMODE = 1 Then
                Debug.Print arrTCoClass(i).prgid, arrTCoClass(i).Name, StringFromGUID(arrTCoClass(i).GUID)
                #End If
                If Len(arrTCoClass(i).prgid) > 0 Then
                    If StrComp(arrTCoClass(i).prgid, ProgIdString, vbTextCompare) = 0 Then
                        flag = True
                    Else
                        If StrComp(arrTCoClass(i).Name, strClassname, vbTextCompare) = 0 Then flag = True
                    End If
                Else
                    If StrComp(arrTCoClass(i).Name, strClassname, vbTextCompare) = 0 Then flag = True
                End If
                If flag Then
                    CpyMem classid, arrTCoClass(i).GUID(0), Len(classid)
                    Exit For
                End If
            Next i
            If i = UBound(arrTCoClass) + 1 Then Exit Function
            ' load the file, if it isn't yet
            hModule = GetModuleHandle(LibraryString)
            If hModule = 0 Then
                hModule = LoadLibrary(LibraryString)
                If hModule = 0 Then Exit Function
            End If
            pFunc = GetProcAddress(hModule, "DllGetClassObject")
            If pFunc = 0 Then Exit Function
            ' call DllGetClassObject to get a class factory for the class ID
            If 0 <> callPointer(pFunc, VarPtr(classid), VarPtr(IID_ClassFactory), VarPtr(obj)) Then Exit Function
            ' IClassFactory VTable
            CpyMem vtbl, ByVal obj, 4
            CpyMem TFactory, ByVal vtbl, Len(TFactory)
            ' create an instance of the object
            If 0 <> callPointer(TFactory.CreateInstance, obj, 0, VarPtr(IID_IUnknown), VarPtr(newobj)) Then
                ' Set IClassFactory = Nothing
                callPointer TFactory.IUnk.Release, obj
                Exit Function
            End If
            ' Set IClassFactory = Nothing
            callPointer TFactory.IUnk.Release, obj
            Set getInstance = newobj
        End Function

  24. #24
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Module for working with COM-Dll without registration.

    how can we use the tlb in dll other than id=1?
    such as CreateObjectEx2("c:\windows\syswow64\vbscript.dll\3", "regexp")

  25. #25
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Module for working with COM-Dll without registration.

    i have found how to do it, both work

    method #1
    Dim reg As Object 'RegExp
    Set reg = CreateObjectEx("c:\windows\syswow64\vbscript.dll", ApiStringtoGUID("{3F4DACA4-160D-11D2-A8E9-00104B365C9F}"))

    method #2
    Set reg = CreateObjectEx2("c:\windows\syswow64\vbscript.dll", _
    "c:\windows\syswow64\vbscript.dll\3", _
    "RegExp")
    Last edited by loquat; Mar 14th, 2022 at 09:50 PM.

  26. #26

  27. #27
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Module for working with COM-Dll without registration.

    Quote Originally Posted by PhuongNam View Post
    Another way is to use the following function... it seems to be similar to New_c.RegFree.GetInstanceEx in Olaf's vbRichClient5.dll
    Below is a part of its many association functions
    The following function was not written by me, but copied from unknown Internet by someone else
    the code you share seems not complete.
    1.IClassFactory and CoClass Type not claimed
    2.getCoClasses and callPointer function not claimed
    3.as well as some api such as cpymem etc.
    Last edited by loquat; Mar 13th, 2022 at 07:45 AM.

  28. #28

  29. #29
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Module for working with COM-Dll without registration.

    both method work as show in #25

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