dcsimg
Page 2 of 2 FirstFirst 12
Results 41 to 63 of 63

Thread: using VbTrickThreading-master examples without the typelibs for Callback and Marshal

  1. #41

    Thread Starter
    Addicted Member
    Join Date
    Apr 2015
    Posts
    182

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    Dear Olaf,

    I added a button to the ExternalControl activex control and added button1 control as follows:
    Private Sub Command1_Click()
    Dim hUser32 As Long
    hUser32 = GetModuleHandle(StrPtr("user32"))
    MsgBox "in button1"
    End Sub

    When I call from AxThreading exe and click on button1 of activex control the declared api GetModuleHandle works
    like a charm without crash even if we don't use RemoveLastDllError module function.Very nice example.Thank you olaf,

    regards,
    JSVenu

  2. #42
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,427

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    If we use any api call with declare in active control project like when we click on a added button in ocx project and open it in exe I think project context for the ocx is also initialized automatically in the new thread and still we have to use your RemoveLastDllError module function to avoid crash due to API usage.Please clarify am I correct.
    When you create an object using DllGetClassObject (the standard ActiveX way) it always initializes the context for current thread.

  3. #43

    Thread Starter
    Addicted Member
    Join Date
    Apr 2015
    Posts
    182

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    Quote Originally Posted by The trick View Post
    When you create an object using DllGetClassObject (the standard ActiveX way) it always initializes the context for current thread.
    Dear Trick,
    Thankyou for the clear clarification.
    regards,
    JSVenu

  4. #44
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,528

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    Quote Originally Posted by jsvenu View Post
    I added a button to the ExternalControl activex control and added button1 control as follows:
    Private Sub Command1_Click()
    Dim hUser32 As Long
    hUser32 = GetModuleHandle(StrPtr("user32"))
    MsgBox "in button1"
    End Sub

    When I call from AxThreading exe and click on button1 of activex control the declared api GetModuleHandle works
    like a charm without crash even if we don't use RemoveLastDllError module function.
    Of course, because the example adheres to the "VB6-COM-STA threading-rules"
    (implicitely, hidden from the User).

    You can write basically the same thing (which adheres to these rules) also with the tricks Helper-module
    (using AX-Dll-Classes instead of Ax-Exe-Classes) -
    but then you'd have to learn, which of the provided "threading-helper-functionality" you'd have to avoid -
    and which parts of it are "safe to use" (to not break those COM-threading-rules).

    Olaf

  5. #45
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,427

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    When I call from AxThreading exe and click on button1 of activex control the declared api GetModuleHandle works
    like a charm without crash even if we don't use RemoveLastDllError module function.
    Code:
    Private Sub cmdCreateThread_Click()
        CloseHandle vbCreateThread(0, 0, AddressOf ThreadProc, 0, 0, 0)
    End Sub
    
    Private Sub Form_Load()
        Me.Caption = App.ThreadID
        Controls.Add("TestOCX.ctlTest", "Ctl1").Visible = True
    End Sub
    Code:
    Option Explicit
    
    Sub Main()
        modMultiThreading.Initialize
        frmMain.Show vbModal
        modMultiThreading.Uninitialize
    End Sub
    
    Public Function ThreadProc( _
                    ByVal l As Long) As Long
        Dim cFrm As frmMain
        
        Set cFrm = New frmMain
        
        cFrm.Show vbModal
            
    End Function
    Name:  testOCX.jpg
Views: 75
Size:  23.5 KB
    The buttons creates a thread with form with external OCX. It requires no administrative right (for EXE), no install (for EXE), shared global variables, etc.

  6. #46

    Thread Starter
    Addicted Member
    Join Date
    Apr 2015
    Posts
    182

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    Dear Trick and Olaf,

    Thank you very much for the nice threading examples along with clear explanation.

    regards,
    JSVenu

  7. #47
    Member
    Join Date
    Jan 2020
    Posts
    55

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    you do like on thread:Controls.Add("TestOCX.ctlTest", "Ctl1").Visible = True

    when i add usercontrol on form by my hand,not use"controls.add"。
    createthread for load the form with usercontrol or ocx,it,s error。
    my english is not good,i can't understand your mean。maybe i need down your code for test.
    ,someone tell me,can use method(EbLoadRunTime
    EbCreateContext
    EbSetContextWorkerThread)

  8. #48

  9. #49
    Member
    Join Date
    Jan 2020
    Posts
    55

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    // This method is called from main thread using proxy-stub layer
    Public Function Initialize( _
    ByRef sPath As String, _
    ByRef sName As String) As Boolean

    Set m_cPlugin = modUnregCOM.CreateObjectEx2(sPath, sPath, sName)
    your method need load ocx?by clsid?
    I want createthread ( address of test) only in stand exe,no need ocx,no need stand dll,no need com dll,no need activex exe.
    my method code lines so much,i want to find a easy way,can you help me?
    Code:
    sub test()
    dim f as form2
    set f=new form2 ' a usercontrol in this form.
    f.show 1
    end sub

  10. #50

  11. #51
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,528

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    Quote Originally Posted by xiaoyao View Post
    I want createthread ( address of test) only in stand exe,
    ...no need ocx,no need stand dll,no need com dll,no need activex exe.
    Why do you want to avoid using other (additional) libraries
    (later shipping with your Exe, e.g. in a \Bin\-sub-folder)?

    You are using VB6 after all - a high-level-language which has its strengths exactly there
    (in glueing selfdescribing COM-Objects and COM-Controls together in a RADish way).

    If it is because of "avoiding to make a proper installer" - then you should learn about regfree-COM mechanisms first.

    VB6 was not made for "normal, free-threading"...
    It supports a different kind of threading instead, which requires you to make use of ActiveX-Dlls
    (or ActiveX-Exes), when you want to play things "by the (VB6)book" (to avoid instabilities).

    Olaf

  12. #52
    Member
    Join Date
    Jan 2020
    Posts
    55

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    where can i download project
    i want test add usercontrol on thread form by toolbar ,not by ocx,how can i do?
    Controls.Add("TestOCX.ctlTest",

  13. #53

    Thread Starter
    Addicted Member
    Join Date
    Apr 2015
    Posts
    182

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    Quote Originally Posted by xiaoyao View Post
    where can i download project
    i want test add usercontrol on thread form by toolbar ,not by ocx,how can i do?
    Controls.Add("TestOCX.ctlTest",
    Dear xiaoyao,

    Goto project ->components and browse for the .ocx file which you want to add to the project
    and select open and then click ok.Automatically it will appear in tool bar which you can add to the form in the standard exe project.

    regards,
    JSVenu

  14. #54
    Member
    Join Date
    Jan 2020
    Posts
    55

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    Code:
    Private Sub cmdCreateThread_Click()
    CloseHandle vbCreateThread(0, 0, AddressOf ThreadProc, 0, 0, 0)
    End Sub

    Private Sub Form_Load()
    Me.Caption = App.ThreadID
    Controls.Add("TestOCX.ctlTest", "Ctl1").Visible = True
    End Sub
    Code:
    Option Explicit

    Sub Main()
    modMultiThreading.Initialize
    frmMain.Show vbModal
    modMultiThreading.Uninitialize
    End Sub

    Public Function ThreadProc( _
    ByVal l As Long) As Long
    Dim cFrm As frmMain

    Set cFrm = New frmMain

    cFrm.Show vbModal

    End Function

    where is the project link for download?

  15. #55

    Thread Starter
    Addicted Member
    Join Date
    Apr 2015
    Posts
    182

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    Quote Originally Posted by xiaoyao View Post
    Code:
    Private Sub cmdCreateThread_Click()
    CloseHandle vbCreateThread(0, 0, AddressOf ThreadProc, 0, 0, 0)
    End Sub

    Private Sub Form_Load()
    Me.Caption = App.ThreadID
    Controls.Add("TestOCX.ctlTest", "Ctl1").Visible = True
    End Sub
    Code:
    Option Explicit

    Sub Main()
    modMultiThreading.Initialize
    frmMain.Show vbModal
    modMultiThreading.Uninitialize
    End Sub

    Public Function ThreadProc( _
    ByVal l As Long) As Long
    Dim cFrm As frmMain

    Set cFrm = New frmMain

    cFrm.Show vbModal

    End Function

    where is the project link for download?
    Dear xiaoyao,

    I am attaching the project.

    You first build the ExternalControl.vbp activex project in the attachment folder and generate ExternalControl.ocx.

    Then open the standard exe project(AxThreading.vbp) and add the ExternalControl.ocx thru project components to the tool bar and then add it to the form in the exe project and build it and run the compiled exe.Click on the button on the form.

    regards,
    JSVenu
    Attached Files Attached Files
    Last edited by jsvenu; Jan 25th, 2020 at 10:54 AM.

  16. #56
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,427

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    // This method is called from main thread using proxy-stub layer
    Public Function Initialize( _
    ByRef sPath As String, _
    ByRef sName As String) As Boolean

    Set m_cPlugin = modUnregCOM.CreateObjectEx2(sPath, sPath, sName)
    your method need load ocx?by clsid?
    I want createthread ( address of test) only in stand exe,no need ocx,no need stand dll,no need com dll,no need activex exe.
    my method code lines so much,i want to find a easy way,can you help me?
    This is other project which i did for yokesee which shows the plugin-based concept with multithreading.
    To create a thread you need to use this module. There are the examples of usage. You don't need any dependencies or dlls. This example just shows how to use an external OCX.

    where can i download project
    I've attached the one. The modMultiThreading module you can get if you go to the link i provided above.
    Attached Files Attached Files

  17. #57

    Thread Starter
    Addicted Member
    Join Date
    Apr 2015
    Posts
    182

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    Quote Originally Posted by xiaoyao View Post
    you do like on thread:Controls.Add("TestOCX.ctlTest", "Ctl1").Visible = True

    when i add usercontrol on form by my hand,not use"controls.add"。
    createthread for load the form with usercontrol or ocx,it,s error。
    my english is not good,i can't understand your mean。maybe i need down your code for test.
    ,someone tell me,can use method(EbLoadRunTime
    EbCreateContext
    EbSetContextWorkerThread
    )
    Dear xiaoyao,

    Here is the Link http://www.devx.com/vb2themax/CodeDownload/19804

    for FreeThreader component for VB6 which uses above bold API in the same order for runtime initialisation in CreateMT and EnableEvents functions in assembly language in the file MULTITHREAD.Asm .
    It is described as follows:
    VB6 does not natively support free threading, but with this ActiveX library you can finally create multiple threads and make them communicate, write delegate functions (similarly to VB.NET) and use Structured Exception Handling. The full source code (in VB6 and Assembler) and some sample projects are provided.

    This is also reply to http://www.vbforums.com/showthread.p...t-UserControl) post #9

    Regarding internal working and stability of this code you can take help from Trick since I have less knowledge in ASM and already he helped me a lot regarding multithreading and he can better understand undocumented API like this.

    regards,
    JSVenu

  18. #58
    Member
    Join Date
    Jan 2020
    Posts
    55

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    stand exe-thread ,can't support (usercontrols),how to fix it?
    it's my thread bbs pagecode is to hard ,and lines to long,use asm,hook)

    http://www.vbforums.com/showthread.p...t-UserControl)

    download :http://www.vbforums.com/attachment.p...3&d=1579799200
    Attached Files Attached Files
    Last edited by xiaoyao; Yesterday at 12:28 PM.

  19. #59
    Member
    Join Date
    Jan 2020
    Posts
    55

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    Quote Originally Posted by The trick View Post
    This is other project which i did for yokesee which shows the plugin-based concept with multithreading.
    To create a thread you need to use this module. There are the examples of usage. You don't need any dependencies or dlls. This example just shows how to use an external OCX.


    I've attached the one. The modMultiThreading module you can get if you go to the link i provided above.
    ==============
    how to add usercontrols on forms object in thread?
    (your project can add ocx,but can't support vb6 usercontrol)

    Code:
    Private obj As Object
    
    Private Sub Command1_Click()
    On Error GoTo ERR
    
    Set obj = Me.Controls.Add("Project1.UserControl1", "UserControl1B")
    obj.Visible = True
    MsgBox obj.Width
      Exit Sub
    ERR:
      MsgBox "ERR:" & ERR.Number & "," & ERR.Description
    End Sub
    
    sub test2
    Dim ctlName As Control
    Set ctlName = Form1.Controls.Add("Project1.UserControl1", "Text1", Form1)
    ctlName.Visible = True
    end sub
    Last edited by xiaoyao; Yesterday at 08:48 PM.

  20. #60
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,427

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    how to add usercontrols on forms object in thread?
    (your project can add ocx,but can't support vb6 usercontrol)
    Seems it's the problem with the runtime. It registers the "Global Factory" thru CoRegisterClassObject from the main STA and when you create an usercontrol it calls CoGetClassObject. CoGetClassObject checks the registered Apartment ID i.e. you can't get this "Global Factory" from the different apartment. The same problem you'll see with ActiveX EXE project type. To avoid this you can for example use Load statement with a control array. Additionally you can set the Threading Model to Apartment (1) in VBHeader.dwThreadFlags when you create a VBHeader. In this case each thread (namely STA) will have its own HXMod internal object like in ActiveX DLL. Only in this case you need to performs additional cleaning like VBCanUnloadNow, etc.

  21. #61
    Member
    Join Date
    Jan 2020
    Posts
    55

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    CoGetClassObject,maybe my chinese friend fix error by hook "CoGetClassObject",use asm set eip,But the code is too long.
    the vb project down here,can you chang for sample?
    thank you very much。
    http://www.vbforums.com/showthread.p...t-UserControl)


    method 2:{HOOK DllFunctionCall} and change argument.(like hook messageboxa,can change msg text or title)
    http://www.m5home.com/bbs/thread-3965-1-1.html
    What do you think about?
    Last edited by xiaoyao; Today at 06:14 AM.

  22. #62
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,427

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    Just change this function as follows:
    Code:
    ' // Create copy of VBHeader and other structures
    ' // The first four bytes contain thread ID. We use that ID to clean unused headers
    Private Function CreateVBHeaderCopy() As Long
        
       . . .
        
        CopyMemory ByVal pHeader, ByVal pVBHeader, &H6A
        
        ' // ++++++++++++++++++++++++++++
        ' // to xiaoyao
        ' // Make Apartment threading model
        ' //
        GetMem4 1&, ByVal pHeader + &H3C
        ' //
        ' // You should ensure extra cleaning like VBDllCanUnloadNow, etc.
        ' // ++++++++++++++++++++++++++++
        
        ' // Update strings offsets
        CopyMemory pNames(0), ByVal pVBHeader + &H58, &H10
        
        . . .
    
    End Function
    Name:  mt_apartment.jpg
Views: 19
Size:  28.5 KB
    Attached Files Attached Files

  23. #63
    Member
    Join Date
    Jan 2020
    Posts
    55

    Re: using VbTrickThreading-master examples without the typelibs for Callback and Mar

    Quote Originally Posted by The trick View Post
    Just change this function as follows:
    Code:
    ' // Create copy of VBHeader and other structures
    ' // The first four bytes contain thread ID. We use that ID to clean unused headers
    Private Function CreateVBHeaderCopy() As Long
        
       . . .
        
        CopyMemory ByVal pHeader, ByVal pVBHeader, &H6A
        
        ' // ++++++++++++++++++++++++++++
        ' // to xiaoyao
        ' // Make Apartment threading model
        ' //
        GetMem4 1&, ByVal pHeader + &H3C
        ' //
        ' // You should ensure extra cleaning like VBDllCanUnloadNow, etc.
        ' // ++++++++++++++++++++++++++++
        
        ' // Update strings offsets
        CopyMemory pNames(0), ByVal pVBHeader + &H58, &H10
        
        . . .
    
    End Function
    Name:  mt_apartment.jpg
Views: 19
Size:  28.5 KB
    Code:
    Public Function GETVBHeaderID() As Long                                      '取VB头,全新的取VB头方法,速度比OPEN文件快得多
        Dim lPtr          As Long, lRet              As Long, isvb              As String, ll                As Long, mdat(1033)        As Byte
        lPtr = VBGetModuleHandle(ByVal 0&)
        isvb = StrConv("VB5!", vbFromUnicode)
        Do
            If ReadProcessMemory(-1, ByVal lPtr, mdat(0), 1034, ll) = 0 Then Exit Function
            lRet = InStrB(mdat, isvb)
            If lRet <> 0 Then Exit Do
            lPtr = lPtr + 1024
        Loop
        GETVBHeaderID = lPtr + lRet - 1
        
    End Function
    
    SUB ThreadTest()
    CreateIExprSrvObj 0, 4, 0
    CoInitializeEx ByVal 0&, ByVal COINIT_APARTMENTTHREADED
    Call VBDllGetClassObject(U1, U2, pVBHeader, pDummy, pIID, pDummy2)
    msgbox "abc"
    dim f as form2 'with usercontrol
    set f=new form2
    f.show 1
    end sub
    
    'in main form
    sub test()
    createthread *,addressof ThreadTest,*
    end sub
    HOW TO ADD YOUR CODE TO My project ( for support usercontrol)?
    my project only use three lines code for createthread.
    not use HeapAlloc,not use tls,not same like you.
    Last edited by xiaoyao; Today at 09:35 AM.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width