Page 4 of 5 FirstFirst 12345 LastLast
Results 121 to 160 of 172

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

  1. #121

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by jsvenu View Post
    Dear Trick,


    In the following attached activex exe code running standalone in modmain.bas we display fMain in modeless way

    Code:
    Sub Main()                              
        If App.TaskVisible Then fMain.Show  
    End Sub
    I add usercontrol to my activex exe standalone project thru Load User Control button as follows:

    Code:
    Private Sub Command1_Click()              
        Controls.Add("AxThreading.UserControl1", "Ctl1").Visible = True             'load usercontrol Control onto this ThreadForm
    End Sub
    When I click on the Load User Control button I get the following error in msgbox

    ---------------------------
    AxThreading
    ---------------------------
    Run-time error '720':

    'AxThreading.UserControl1' is not a valid control type
    ---------------------------
    OK
    ---------------------------





    But when I make fMain to display in modal fashion as follows and click on the Load User Control button it works fine.

    Sub Main()
    If App.TaskVisible Then fMain.Show vbModal
    End Sub


    1. Please clarify how to make this activex exe application to work when fMain is displayed in modeless way.


    When I click on Create and show an additional threaded Form button in the displayed form I get another instance of the same form displayed in new thread.

    When I click on the Load User Control button in this new form I get the following error

    ---------------------------
    AxThreading
    ---------------------------
    Run-time error '339':

    Component '' or one of its dependencies not correctly registered: a file is missing or invalid
    ---------------------------
    OK
    ---------------------------

    2. Please clarify how to make this work fine in this new form displayed in new thread.


    regards,
    JSVenu
    Dear Trick,
    For changing the activex exe to apartment model threading can we get vbheader of the activex exe in the same way as
    standard exe using the same GetVBHeader function of modmultithreading module so that we can see that usercontrol works in main thread form and in new thread form.Please clarify.

    regards,
    JSVenu

  2. #122
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    Quote Originally Posted by The trick View Post
    xiaoyao, it's difficult to understand you, sorry. What do you want? Do you ask something or?
    why standard exe only use "VBDllGetClassObject",but standard dll need "UserDllMain"

    Private Function InitRuntime(ByVal lpInst As Long, ByVal lpUnk As Long, ByVal lpVBHdr As Long, ByVal hInstDll As Long, _
    ByVal fdwReason As Long, ByVal lpvReserved As Long) As Long
    Dim iid As uuid
    Dim clsid As uuid

    InitRuntime = UserDllMain(lpInst, lpUnk, hInstDll, fdwReason, ByVal lpvReserved)
    If InitRuntime Then
    vbCoInitialize ByVal 0&
    iid.data4(0) = &HC0: iid.data4(7) = &H46 ' IUnknown
    VBDllGetClassObject lpInst, lpUnk, lpVBHdr, clsid, iid, 0 ' Инициализация потока
    End If
    End Function
    For apartment threade

  3. #123

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by jsvenu View Post
    Dear Trick,
    For changing the activex exe to apartment model threading can we get vbheader of the activex exe in the same way as
    standard exe using the same GetVBHeader function of modmultithreading module so that we can see that usercontrol works in main thread form and in new thread form.Please clarify.

    regards,
    JSVenu
    Dear Trick,
    If I try to change the activex exe(standalone mode) code for the link http://www.vbforums.com/attachment.p...1&d=1580720396 as follows:


    Sub Main()
    modMultiThreading.Initialize
    If App.TaskVisible Then fMain.Show
    End Sub


    where GetVBHeader() is modified as


    ' // Get VBHeader structure
    Private Function GetVBHeader() As Long
    Dim ptr As Long
    Dim bThreading As Long
    Dim tempheader As Long
    Dim lOldProtect As Long
    ' // Get e_lfanew
    GetMem4 ByVal hModule + &H3C, ptr
    ' // Get AddressOfEntryPoint
    GetMem4 ByVal ptr + &H28 + hModule, ptr
    ' // Get VBHeader
    GetMem4 ByVal ptr + hModule + 1, tempheader
    'set to apartment model to support user control
    GetMem1 ByVal tempheader + &H3C, bThreading
    bThreading = bThreading Or 1
    VirtualProtect ByVal tempheader, 4, PAGE_READWRITE, lOldProtect
    GetMem1 bThreading, ByVal tempheader + &H3C
    VirtualProtect ByVal ptr, 4, lOldProtect, 0
    GetVBHeader = tempheader
    End Function



    when I built and run compiled exe I get the following error in msgbox:


    ---------------------------
    AxThreading
    ---------------------------
    Run-time error '369':

    Operation not valid in an ActiveX DLL
    ---------------------------
    OK
    ---------------------------



    Please clarify.

    regards,
    JSVenu
    Last edited by jsvenu; Feb 4th, 2020 at 05:33 AM.

  4. #124
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    how to run createthread in activex.exe, and support usercontrols in vb6 form1.frm (by createthread show form1)
    =======================
    Set OBJ = Controls.Add("actexexc2.UserControl1", "UserControl1AA")
    'err: 720,' actexexc2. Usercontrol1 'is not a valid control type (load by from)
    ========
    GetMem4 ByVal ptr + hModule + 1, lpVBHeader
    VBDllGetClassObject VarPtrHModule, 0, lpVBHeader, 0&, Iid, 0

    'display in multithread: err: 339, part' 'or one of its attachments is not registered correctly: a file is missing or invalid
    (load by Createthread)
    ========
    GetMem4 1&, ByVal NewVBHeader_Heap + &H3C '加的,支持自定义控件
    VBDllGetClassObject VarPtrHModule, 0, NewVBHeader_Heap, 0&, Iid, 0
    'heap multithreading error: err: 438, object does not support this property or method
    ( heap by creathread)
    =======================
    chinese:'ERR:720,'actexexc2.UserControl1' 不是有效控件类型
    '在多线程中显示:ERR:339,部件 '' 或其附件之一不能正确注册:一个文件丢失或无效
    'heap多线程出错:ERR:438,对象不支持该属性或方法
    Set OBJ = Controls.Add("actexexc2.UserControl1", "UserControl1AA")
    Last edited by xiaoyao; Feb 4th, 2020 at 07:46 AM.

  5. #125
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    hHeap = GetProcessHeap()
    hHeap = HeapCreate(0, 0, 65536)
    With HEAP, you can load custom controls, but it's unstable,

    The first time multithreading was successful, closed and reopened, not the second time

  6. #126
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    hHeap = GetProcessHeap()
    hHeap = HeapCreate(0, 0, 65536)
    With HEAP, you can load custom controls, but it's unstable,

    The first time multithreading was successful, closed and reopened, not the second time

    maybe activex.exe not use the same lSizeOfHeaders ?

    lSizeOfHeaders = &H6A + &H23C + &H54 + &HC + 4
    GetMem4 ByVal lpVBHeader + &H30, pOldProjInfo 'vb6 ide Can't Run
    GetMem4 ByVal pOldProjInfo + &H4, pOldObjTable
    GetMem4 ByVal pOldObjTable + &H30, pOldDesc
    GetMem2 ByVal pOldObjTable + &H2A, lModulesCount
    lSizeOfHeaders = lSizeOfHeaders + &H30 * lModulesCount

    GetMem4 1&, ByVal NewVBHeader_Heap + &H3C '加的,支持自定义控件

  7. #127
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

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

    Quote Originally Posted by jsvenu View Post
    If I try to change the activex exe(standalone mode) code ...
    ...where GetVBHeader() is modified ...
    ...I get the following error ...
    Well, you've changed a perfectly fine VB6-threading-example (which does everything by the book),
    into something which uses the "VB-Header-hack" - and thus instabilities are normal.

    Don't do that kind of hacking.

    It is not needed at all, to accomplish proper threading in VB6.

    Olaf

  8. #128
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    Quote Originally Posted by Schmidt View Post
    Well, you've changed a perfectly fine VB6-threading-example (which does everything by the book),
    into something which uses the "VB-Header-hack" - and thus instabilities are normal.

    Don't do that kind of hacking.

    It is not needed at all, to accomplish proper threading in VB6.

    Olaf
    active.exe may need to make a standard dll, using the multi-threaded api in the dll.

  9. #129
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    Quote Originally Posted by jsvenu View Post
    Dear Trick,
    If I try to change the activex exe(standalone mode) code for the link http://www.vbforums.com/attachment.p...1&d=1580720396 as follows:


    Sub Main()
    modMultiThreading.Initialize
    If App.TaskVisible Then fMain.Show
    End Sub


    where GetVBHeader() is modified as


    ' // Get VBHeader structure
    Private Function GetVBHeader() As Long
    Dim ptr As Long
    Dim bThreading As Long
    Dim tempheader As Long
    Dim lOldProtect As Long
    ' // Get e_lfanew
    GetMem4 ByVal hModule + &H3C, ptr
    ' // Get AddressOfEntryPoint
    GetMem4 ByVal ptr + &H28 + hModule, ptr
    ' // Get VBHeader
    GetMem4 ByVal ptr + hModule + 1, tempheader
    'set to apartment model to support user control
    GetMem1 ByVal tempheader + &H3C, bThreading
    bThreading = bThreading Or 1
    VirtualProtect ByVal tempheader, 4, PAGE_READWRITE, lOldProtect
    GetMem1 bThreading, ByVal tempheader + &H3C
    VirtualProtect ByVal ptr, 4, lOldProtect, 0
    GetVBHeader = tempheader
    End Function



    when I built and run compiled exe I get the following error in msgbox:


    ---------------------------
    AxThreading
    ---------------------------
    Run-time error '369':

    Operation not valid in an ActiveX DLL
    ---------------------------
    OK
    ---------------------------



    Please clarify.

    regards,
    JSVenu

    1. Create multiple threads in activex.exe. You can only succeed once, and then the application crashes.
    2. If you want to make a standard DLL (vbdll. DLL), add the interface API (createthread? API) for creating threads,
    Then pass (app. Hsinstance, vbheader) to DLL in activex.exe and call createthread? API
    You can also create multiple threads in a row, but you cannot use global variables.
    3. You can add some global variables (public ABC as long) to the standard DLL,
    The output function then accesses the variable / Export: getabc.
    If you take out the process address of class 1 of activex.exe and call it directly with a thread, you may be able to modify the global variables

    1. создание нескольких потоков внутри ACTIVEX. EXE может быть успешным только один раз, после чего приложение рухнет.
    2, если выбран стандартный DLL (vbdll.dll), добавить API (CreateThread tmu api) для создания интерфейса дискуссии;
    затем в ACTIVEX. EXE (App. HInstance, VBHeader) для DLL, call CreateThread au api
    Это также позволяет создавать несколько потоков подряд, но не может использовать глобальные переменные.
    3 в стандартный DLL можно добавить глобальные переменные (public ABC AS LONG);
    затем функция вывода позволяет получить доступ к переменной / export: GetAbc.
    Если взять операционные адреса класса Class1, то вызовите непосредственно дискуссии, возможно, можно изменить глобальные переменные

    chinese:
    1,在ACTIVEX.EXE里面创建多线程,只能成功一次,然后应用程序就崩溃了。
    2,如果做一个标准DLL(vbdll.dll),添加创建线程的接口API(CreateThread_api),
    然后在ACTIVEX.EXE里面传递(App.hInstance,VBHeader)给DLL,调用CreateThread_api
    这样也可以连续多次创建多线程,但是无法使用全局变量。
    3,可以在标准DLL里面添加一些全局变量(public ABC AS LONG ),
    然后输出函数进行存取变量 /export:GetAbc。
    如果把Activex.exe的Class1这个类的过程地址取出来,直接用线程调用,说不定可以修改全局变量

  10. #130

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by Schmidt View Post
    Well, you've changed a perfectly fine VB6-threading-example (which does everything by the book),
    into something which uses the "VB-Header-hack" - and thus instabilities are normal.

    Don't do that kind of hacking.

    It is not needed at all, to accomplish proper threading in VB6.

    Olaf
    Dear Olaf,

    I am trying to make the activex exe application support user control in the same application because it is not working as I already mentioned.That is why I asked Trick for the solution since he has already helped me to do it in standard exe.You can tell me how to support the user control in the application.

    regards,
    JSVenu

  11. #131

  12. #132
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

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

    Quote Originally Posted by jsvenu View Post
    I am trying to make the activex exe application support user control in the same application because it is not working as I already mentioned.
    I thought you found a workaround already (by showing these Forms modally)...

    But anyways, there's no hacks required to make "Project-Private-UserControls" work with threaded Forms.
    You just have to embrace and learn about:
    - VB6-Classes
    - how to implement and test them as "Private Classes" in an isolated Test-Project
    - how to later move - and encapsulate them in Ax-Dlls (after they become stable)
    - and how to load Ax-Classes from such Ax-Dlls regfree

    The VB6-STA-based threading-model (which is all about "Public Classes on their own Threads"), works rock-solid -
    whereas attempts at FreeThreading in VB6 will always be "fragile" at best.

    So, the solution for your "Private UC on a threaded Form" is, to move the threaded Form out of the Ax-Exe-Project...
    And into a separate ActiveX-Dll-Project (together with any Private UCs you want to use on these threaded Forms).

    I've added a second example (which shows how to do that) to the AxExeThreading article here:
    http://www.vbforums.com/showthread.p...-(simple-Demo)


    HTH

    Olaf

  13. #133
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    Quote Originally Posted by The trick View Post
    I'll answer later don't have time right now.
    for my testing,activex.exe can support createthread。but can't add usercontrol on form2.frm。 I can make standard exe first,add usercontrols to forms,than change to activex.exe。
    now only can add usercontrol by code "controls.add(*)".
    maybe activex.exe is a special format pe code exe。it's sta thread?createthread by a standard dll api (vbdll.dll ) ,so can't use Global variables when running in createthread。
    without standard dll ,it's only can run once createthread,when run the second times,crashed!mabe need some hake code for change vb header?

    but it There must be a way to support. .(like excel must be can support createthread)

    only vb6 make more question, like not support standard createthread.
    Microsoft engineers left too many issues at the time and gave up vb6 without handling them.

  14. #134
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    Quote Originally Posted by Schmidt View Post
    I thought you found a workaround already (by showing these Forms modally)...

    But anyways, there's no hacks required to make "Project-Private-UserControls" work with threaded Forms.
    You just have to embrace and learn about:
    - VB6-Classes
    - how to implement and test them as "Private Classes" in an isolated Test-Project
    - how to later move - and encapsulate them in Ax-Dlls (after they become stable)
    - and how to load Ax-Classes from such Ax-Dlls regfree

    The VB6-STA-based threading-model (which is all about "Public Classes on their own Threads"), works rock-solid -
    whereas attempts at FreeThreading in VB6 will always be "fragile" at best.

    So, the solution for your "Private UC on a threaded Form" is, to move the threaded Form out of the Ax-Exe-Project...
    And into a separate ActiveX-Dll-Project (together with any Private UCs you want to use on these threaded Forms).

    I've added a second example (which shows how to do that) to the AxExeThreading article here:
    http://www.vbforums.com/showthread.p...-(simple-Demo)


    HTH

    Olaf
    Maybe activex exe is a packaged rot model? If we first develop a rot program instead of activex.exe, then we can achieve perfect multithreading as we want, it is very convenient to support usercontrol。
    chinese:也许 activex exe 是一种包装好的 rot 模型?假如我们单独先开发一个 rot 程序代替 activex.exe ,这样就可以随心所欲的实现完美的多线程了,很方便支持 usercontrol

  15. #135
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

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

    Quote Originally Posted by xiaoyao View Post
    vb6 make more question, like not support standard createthread
    Microsoft engineers left too many issues at the time and gave up vb6 without handling them.
    The CreateThread-API is useful only from within languages, which support FreeThreading.

    There is absolutely no point in "forcing" VB6 to handle FreeThreading as well,
    because it was not designed for that ... instead it comes with its own "COM-Class based threading-support",
    which works differently - but in the end allows threading as well.

    Instead of the CreateThread-API, you'll have to use a "CreateObjectFromPublicClassOnThreadedSTA" kind of call:
    - which can be done either via CreateObject (called from within an AxExe-ProjectType)
    - or via your own "STA-establishing implementation" in a Standard- or AxDll

    This "COM-Class based threading-support" in VB6 works stable, requires no hacks -
    and makes it easy for threading-newbies to implement solid threading-solutions,
    because no "synchronizing" has to be implemented for cross-thread-communication.

    There are no "issues" with VB6 threading, if there are - I'd really like to learn about them.

    Just think about, what you'd like to implement as a "threaded solution" in VB6 (a concrete, useful scenario) -
    and we can show you how to do that.

    Olaf

  16. #136

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by Schmidt View Post
    I thought you found a workaround already (by showing these Forms modally)...

    But anyways, there's no hacks required to make "Project-Private-UserControls" work with threaded Forms.
    You just have to embrace and learn about:
    - VB6-Classes
    - how to implement and test them as "Private Classes" in an isolated Test-Project
    - how to later move - and encapsulate them in Ax-Dlls (after they become stable)
    - and how to load Ax-Classes from such Ax-Dlls regfree

    The VB6-STA-based threading-model (which is all about "Public Classes on their own Threads"), works rock-solid -
    whereas attempts at FreeThreading in VB6 will always be "fragile" at best.

    So, the solution for your "Private UC on a threaded Form" is, to move the threaded Form out of the Ax-Exe-Project...
    And into a separate ActiveX-Dll-Project (together with any Private UCs you want to use on these threaded Forms).

    I've added a second example (which shows how to do that) to the AxExeThreading article here:
    http://www.vbforums.com/showthread.p...-(simple-Demo)


    HTH

    Olaf
    Dear olaf,

    First thankyou for the example.

    As I said when we add a button to fThreaded form in activex dll project MyForms and try to add the usercontrol through the button as follows:


    Code:
    Private Sub Command1_Click()
        On Error GoTo err1
        Controls.Add("MyForms.ucTest", "Ctl2").Visible = True
        Exit Sub
    err1:
        MsgBox "err:" & Err.Number & "," & Err.Description & "," & Err.Source
    End Sub

    which adds usercontrol to the form at runtime we get the following error( in msgbox )when we run the app in compiled mode and click on this button on displayed fThreaded form.

    ---------------------------
    MyForms
    ---------------------------
    err:711,Invalid class string.
    Looking for object with ProgID: MyForms.ucTest,MyForms
    ---------------------------
    OK
    ---------------------------



    This is the reason I asked Trick for help.


    regards,
    JSVenu
    Last edited by jsvenu; Feb 6th, 2020 at 12:41 AM.

  17. #137
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

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

    Quote Originally Posted by jsvenu View Post
    As I said when we add a button to fThreaded form in activex dll project MyForms and try to add the usercontrol through the button as follows:
    ...
    ...we get the following error( in msgbox )when we run the app in conpiled mode and click on this button on displayed fThreaded form.

    err:711,Invalid class string.
    Looking for object with ProgID: ucTest.ctlTest,MyForms
    No, I cannot reproduce that...
    As said, this kind of threading is as safe as can be.

    So (just in case), you should *not* include any of tricks "threading-support" modules -
    neither into the AxExeThreading2-project, nor should they be included in MyForms-Project.
    They are not needed at all.

    My guess is, that you need to recompile the OCX-Project (or re-register the OCX).
    Or your ProgID ("ucTest.ctlTest") is wrong.

    If I try that with "wellknown ProgIDs" (for the IE-WebBrowserControl, or Krools CCR-OCX),
    it works without any problem (in IDE and compiled).

    Here is the complete code of fThreaded.frm in Ax-Dll MyForms:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Caption = Caption & " ThreadID: " & App.ThreadID
    End Sub
    
    Private Sub Command1_Click()
      Controls.Add("Shell.Explorer.2", "WebBrowser1").Visible = True
      Controls.Add("VBCCR16.TextBoxW", "TextBox1").Visible = True
    End Sub
    HTH

    Olaf

  18. #138

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by Schmidt View Post
    No, I cannot reproduce that...
    As said, this kind of threading is as safe as can be.

    So (just in case), you should *not* include any of tricks "threading-support" modules -
    neither into the AxExeThreading2-project, nor should they be included in MyForms-Project.
    They are not needed at all.

    My guess is, that you need to recompile the OCX-Project (or re-register the OCX).
    Or your ProgID ("ucTest.ctlTest") is wrong.

    If I try that with "wellknown ProgIDs" (for the IE-WebBrowserControl, or Krools CCR-OCX),
    it works without any problem (in IDE and compiled).

    Here is the complete code of fThreaded.frm in Ax-Dll MyForms:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Caption = Caption & " ThreadID: " & App.ThreadID
    End Sub
    
    Private Sub Command1_Click()
      Controls.Add("Shell.Explorer.2", "WebBrowser1").Visible = True
      Controls.Add("VBCCR16.TextBoxW", "TextBox1").Visible = True
    End Sub
    HTH

    Olaf
    Dear Olaf,

    I already corrected the ProgID to MyForms.ucTest in the post #136 but I was getting the same error which I solved by using Trick's post
    http://www.vbforums.com/showthread.p...-Marshal/page2 #71
    Thankyou for the example.

    regards,
    JSVenu

  19. #139
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    Why haven't you moved in these two days?

  20. #140
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,797

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

    Sorry for my long delay.

    jsvenu, my module is intended to work with threading using Standard EXE projects. Why do you need this module for an AxEXE if the AxExe can create a thread without it (see Olaf's example)? Please tell me the reason and i give the solution. I gave you the example how to do it in STD EXE.

    why standard exe only use "VBDllGetClassObject",but standard dll need "UserDllMain"
    Because if you want to initialize the runtime you need to call CThreadPool::InitDllAccess which is in VBDllGetClassObject/ThunRTMain

    Well, you've changed a perfectly fine VB6-threading-example (which does everything by the book),
    into something which uses the "VB-Header-hack" - and thus instabilities are normal.
    What's the hack exactly? Okay, we don't doubt your "perfectly fine VB6-threading-example" (PFVB6TE) works well but jsvenu want to make it worked with the private controls.

    But anyways, there's no hacks required to make "Project-Private-UserControls" work with threaded Forms.
    You just have to embrace and learn about:
    - VB6-Classes
    - how to implement and test them as "Private Classes" in an isolated Test-Project
    - how to later move - and encapsulate them in Ax-Dlls (after they become stable)
    - and how to load Ax-Classes from such Ax-Dlls regfree
    Hmmm... Isn't that the "crutch"? The potential user just want to use a private UserControl like he added in the project. He don't want any external DLL/OCX and any additional code to implement the "PFVB6TE (which does everything by the book)".

    The VB6-STA-based threading-model (which is all about "Public Classes on their own Threads"), works rock-solid -
    whereas attempts at FreeThreading in VB6 will always be "fragile" at best.
    Why then the "PFVB6TE" doesn't work with private controls?

    So, the solution for your "Private UC on a threaded Form" is, to move the threaded Form out of the Ax-Exe-Project...
    And into a separate ActiveX-Dll-Project (together with any Private UCs you want to use on these threaded Forms).

    I've added a second example (which shows how to do that) to the AxExeThreading article here:
    http://www.vbforums.com/showthread.p...-(simple-Demo)
    Okay, thank you. But you gave the example which contains the Form with the control in the AxDll. I think the question was how to load a private control to the AxExe form.

    There is absolutely no point in "forcing" VB6 to handle FreeThreading as well,
    because it was not designed for that ... instead it comes with its own "COM-Class based threading-support",
    which works differently - but in the end allows threading as well.
    Okay. But an application can work with an environment which requires such FreeThreading like callbacks etc (like DirectShow, WinInet etc).

    This "COM-Class based threading-support" in VB6 works stable, requires no hacks -
    and makes it easy for threading-newbies to implement solid threading-solutions,
    because no "synchronizing" has to be implemented for cross-thread-communication.
    Okay, if it works stable why jsvenu can't load a private control? Olaf, my module is intended for using Threading in Standard-EXE projects. It also provides the minimal framework to produce the behavior like in AxExe/AxDll projects which isn't required "synchronizing". In truth, COM does all synchronization regardless the project type not VB6. It isn't replacement for AxExe/AxDll solutions like you suggested.

  21. #141

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by The trick View Post
    Sorry for my long delay.

    jsvenu, my module is intended to work with threading using Standard EXE projects. Why do you need this module for an AxEXE if the AxExe can create a thread without it (see Olaf's example)? Please tell me the reason and i give the solution. I gave you the example how to do it in STD EXE.
    Dear Trick,

    Thankyou for the reply.

    The first example I learnt in vb6 multithreading was thru activex exe.Olaf's example remainded me that again and since you helped(by making a mention of activex exe also same problem occurs) in how to solve when Xiaoyao asked you in standard exe , I thought I can try the same with Olaf's activex exe example also which I finally solved using http://www.vbforums.com/showthread.p...-(simple-Demo) #16 using your module with modification to apartment model in GetVBHeader module function.
    But the only clarification required for me is how to avoid global variables from being cleared in activex exe since there I did not use CreateVBHeaderCopy module function.


    regards,
    JSVenu

  22. #142
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,797

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

    But the only clarification required for me is how to avoid global variables from being cleared in activex exe since there I did not use CreateVBHeaderCopy module function.
    You can't because all the variables are isolated by TLS. Only artificially. If you want to use shared variables you need to use either StandardEXE or Activex-DLL (single threaded) project types. You could to get the pointer to a variable in other apartment and read/write to/from it.

  23. #143

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by The trick View Post
    You can't because all the variables are isolated by TLS. Only artificially. If you want to use shared variables you need to use either StandardEXE or Activex-DLL (single threaded) project types. You could to get the pointer to a variable in other apartment and read/write to/from it.
    Dear Trick,

    Thankyou for the reply. Can you show me a example code for to get the pointer to a variable in other apartment and read/write to/from it.

    regards,
    JSVenu

  24. #144

  25. #145

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by The trick View Post
    Why do you need that? If you want to use shared variable just use STD-EXE and my module.
    Dear Trick,
    I am asking this in the sense that since vb6 also supports activex exe project type and if we can use multithreading in a better way here also We can make work in activex exe in a comfortable way rather than working in restricted way and avoiding the activex exe project completely for multithreading since it is not supporting global variables.

    regards,
    JSVenu

  26. #146
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,797

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

    Dear Trick,
    I am asking this in the sense that since vb6 also supports activex exe project type and if we can use multithreading in a better way here also We can make work in activex exe in a comfortable way rather than working in
    restricted way and avoiding the activex exe project completely for multithreading since it is not supporting global variables.
    What do you expected if you make shared variables? It becomes StdExe with restrictions like you have with my module. Do you see the restrictions of AxExe? Do you see the restrictions of VbTrickThreading? What's the more comfortable with AxExe compared with StdExe?

  27. #147

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by The trick View Post
    What do you expected if you make shared variables? It becomes StdExe with restrictions like you have with my module. Do you see the restrictions of AxExe? Do you see the restrictions of VbTrickThreading? What's the more comfortable with AxExe compared with StdExe?
    Dear Trick,

    I am not comparing std exe and actx exe in the sense of comfort.
    I am asking suppose we are already working in activex exe project and want to use module level global variables in the project .How to access them across apartments without being cleared in different threads.

    regards,
    JSVenu

  28. #148
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,797

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

    By rules you should pass the data between COM-calls. Just if you need to transmit data to other apartment you should call a method of object in other apartment and pass your variable. Marshaling will do all the work to transmit the data and make copy (if need). It isn't safe to have shared global variables because you always should marshal the data. But if you want you can pass the pointer to apartment by a COM-call and then use it from other apartment.

  29. #149

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by The trick View Post
    By rules you should pass the data between COM-calls. Just if you need to transmit data to other apartment you should call a method of object in other apartment and pass your variable. Marshaling will do all the work to transmit the data and make copy (if need). It isn't safe to have shared global variables because you always should marshal the data. But if you want you can pass the pointer to apartment by a COM-call and then use it from other apartment.
    Dear Trick,
    I can understand that we can use marshalling in the sense it uses GIT and using comarshal... and counmarshal.. api we can access data.But I did not understand passing the pointer to apartment by a COM-call and then use it from other apartment.Can you explain me by providing a simple example code.

    regards,
    JSVenu

  30. #150
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    Quote Originally Posted by jsvenu View Post
    Dear Trick,

    Thankyou for the reply. Can you show me a example code for to get the pointer to a variable in other apartment and read/write to/from it.

    regards,
    JSVenu
    in activex.exe( clsid roject1.class1 ) ,you have a variable likeublic str1 as string,if you create a new object (thread2obj =createobject("project1.class1")) in new thread ,Normal way we can’t collect that variable content .
    but we can use public strarr(x) as string to read write value,then str1 changed。first,we need call thread2obj.setptr(objptr(str1))
    ,x=***
    or share a class or form to all New thread.

    Other methodsispCallFunc

    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
    Last edited by xiaoyao; Feb 10th, 2020 at 05:56 AM.

  31. #151
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    Because if you want to initialize the runtime you need to call CThreadPool::InitDllAccess which is in VBDllGetClassObject/ThunRTMain

    mabe we can hook api "VBDllGetClassObject",like your vbcreatethread "tlssetvalue+VBDllGetClassObject",
    maybe vb6 use tlssetvalue The same context is intentionally blocked, so global variables cannot be shared anymore.

  32. #152
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    in activex.exe vb6 certainly has a way to achieve multi-threaded and custom controls, ocx controls, is more difficult.
    chinese:vb6肯定有办法实现activex exe的多线程和自定义控件,ocx 控件,就是难度比较大

  33. #153

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by xiaoyao View Post
    in activex.exe vb6 certainly has a way to achieve multi-threaded and custom controls, ocx controls, is more difficult.
    chinese:vb6肯定有办法实现activex exe的多线程和自定义控件,ocx 控件,就是难度比较大
    Dear xiaoyao,

    OCX controls problem in activex exe already solved link http://www.vbforums.com/showthread.p...-(simple-Demo) #16

    regards,
    JSVenu

  34. #154
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    Quote Originally Posted by jsvenu View Post
    Dear xiaoyao,

    OCX controls problem in activex exe already solved link http://www.vbforums.com/showthread.p...-(simple-Demo) #16

    regards,
    JSVenu
    Code:
    ActivexExeThread.bas
    Public Src As String '主变量
    Public MEM(0) As String
    Public x As Long
    
    Public ABC As Long, X2 As Long
    Public AbcArr(0) As Long
    
    in thread forms:
    Private Sub ShowSrcAbc_Click()
    Dim OldAbc As Long
    'AbcArr(X2)=abc
    'MEM(x) =src
    OldAbc = AbcArr(X2)
    MEM(x) = "test:" & Now
    AbcArr(X2) = AbcArr(X2) + 1
    MsgBox "Src=" & MEM(x) & vbCrLf & "Old Abc=" & OldAbc & vbCrLf & "New ABC=" & AbcArr(X2), , "ThreadID = " & App.ThreadID
    End Sub
    
    in main form:
    MsgBox "Src=" & Src & vbCrLf & "ABC=" & ABC, , "threadid=" & App.ThreadID

  35. #155
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    Quote Originally Posted by jsvenu View Post
    Dear Trick,
    I can understand that we can use marshalling in the sense it uses GIT and using comarshal... and counmarshal.. api we can access data.But I did not understand passing the pointer to apartment by a COM-call and then use it from other apartment.Can you explain me by providing a simple example code.

    regards,
    JSVenu
    I found a way to hake vb6 activex.exe,can support public abc as string(The global variable) for every thread ,every activex.exe objects from by createobject("project1.class1")
    it like standard exe, support All the multi-threading tricks,The only difference is { it's a activex.exe}
    Last edited by xiaoyao; Feb 10th, 2020 at 02:13 PM.

  36. #156

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by xiaoyao View Post
    I found a way to hake vb6 activex.exe,can support public abc as string(The global variable) for every thread ,every activex.exe objects from by createobject("project1.class1")
    it like standard exe, support All the multi-threading tricks,The only difference is { it's a activex.exe}

    http://www.vbforums.com/showthread.p...=1#post5451681 #2

  37. #157
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    Application 2: Detailed analysis of vb header structure
    SoftSnoop2009应用二:详细解析vb头结构
    https://bbs.pediy.com/thread-101547.htm

  38. #158
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,797

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

    I can understand that we can use marshalling in the sense it uses GIT and using comarshal... and counmarshal.. api we can access data.But I did not understand passing the pointer to apartment by a COM-call and then use it from other apartment.Can you explain me by providing a simple example code.
    If you want to use shared data you can use a shared section like i did here. Then you can map an array to that section and all the instances will have the shared data.

  39. #159

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

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

    Quote Originally Posted by The trick View Post
    If you want to use shared data you can use a shared section like i did here. Then you can map an array to that section and all the instances will have the shared data.
    Dear trick,
    Thankyou for the sample.
    regards,
    JSVenu

  40. #160
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

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

    Quote Originally Posted by Schmidt View Post
    Well, you've changed a perfectly fine VB6-threading-example (which does everything by the book),
    into something which uses the "VB-Header-hack" - and thus instabilities are normal.

    Don't do that kind of hacking.

    It is not needed at all, to accomplish proper threading in VB6.

    Olaf
    Microsoft does not continue to upgrade vb6 ide, does not support multithreading, does not support standard dll, does not support console programs, and does not support 64-bit program development. Many programmers have implemented these functions one by one, without ide source code, can only use some similar hackers, assemblies, secure arrays, pointers and other methods, and the use is also very stable. It cannot be said that these people are useless and that they have invested a lot of time and technology. It's not just standard exe that supports multithreading, standard dll,com dll,activex.exe,ocx controls, and vba,vbs, all supports multithreading. Isn't that a very meaningful thing? It's also very interesting. No one provides funding or sponsorship. I understand this kind of person as "geek". One developer spent five years developing a vb6-like ide "visualFreebasic" that supports multithreading, pointers, 64-bit compilation, and continues to develop, updating dozens of versions. I think it makes a lot of sense.

Page 4 of 5 FirstFirst 12345 LastLast

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