dcsimg
Page 3 of 4 FirstFirst 1234 LastLast
Results 81 to 120 of 121

Thread: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Trick)

  1. #81

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Schmidt,
    Really I appreciate your code.
    I tried to modify the code in order to show an instance of new for(formapp) from the thread by initializing it in ThreadInitDirectCOM UDT as follows in MyApp

    application:

    Private Type ThreadInitDirectCOM
    Param As Long 'User-Param (given into the ThreadMain-Method of the COM-Dll)
    hThread As Long 'filled from Thread (instantly, after STARTCOMOBJECT() returns)
    ThreadID As Long 'filled from Thread (if fully initialized, some msec after STARTCOMOBJECT())
    Reserved(0 To 127) As Long

    'userdefined Params can be placed here...
    Form As Object 'form object added
    FPS As Long 'will reflect the current FPS of the Remote-Thread
    CancelThread As Boolean 'will be used to signalize Thread-Cancelling to the Remote-Thread
    End Type

    In the class i added code to put formapp object in shared memory as follows:

    Private Sub Class_Initialize() 'prepare the TI-Array (which has only a single "Index-Slot" and is shared with the Remote-Thread)
    ReDim TI(0 To 0) 'we allocate the SharedMem-Array here in the Main-Thread
    Set TI(0).Form = New Formapp' new formapp object added
    TI(0).Param = ArrPtr(TI) 'the Param-Member is, what gets passed into the ThreadMain-Function of the Remote-Class
    End Sub

    In the ThreadLib project I retrived formapp instance from shared memory as follows:

    Public Function ThreadMain(ByVal Param As Long) As Long
    BindArray TI, Param 'span TI virtually over the same Memory as occupied by the TI-Array which was allocated in the Main-Threads ThreadWrapper-Class
    ' Set fThread.Thread = Me 'hand a reference of this Class-Instance over into the Thread-Form too
    ' fThread.Caption = "ThreadID: " & App.ThreadID 'update the ThreadForms Caption with the ThreadID of this Thread
    ' fThread.Show vbModal 'show the ThreadForm modally
    ' Set fThread.Thread = Nothing
    Set frm = TI(0).Form 'pick form from shared memory and
    frm.Show 1 //display but form not displayed.

    ReleaseArray TI 'avoid double-freeing (since the TI-Array is already freed in the MainThreads ThreadWrapper-Instance)
    End Function

    I am sending both MyApp and ThreadLib in VB6ThreadingDirectCOM.zip (without dlls,libs and exes) as attachment.
    Please clarify why I am not able to display form using shared memory.
    The application crashes when I make MyApp.exe and run it.
    Attached Files Attached Files

  2. #82

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Arnoutdv,
    Thankyou.
    I am also not being paid for this technical discussions and I sincerely appreciate try and then only ask for clarification
    in order to improve and share my knowlege technically and there is no other intention.

  3. #83
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,050

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Quote Originally Posted by jsvenu View Post
    I tried to modify the code in order to show an instance of new for(formapp) from the thread by initializing it in ThreadInitDirectCOM UDT as follows in MyApp
    There was no need for an example (which BTW would not work, since the shared Memory
    in the UDT-based SafeArray may not contain Object-Members...).

    All you have to do, to get help here is, to answer the questions which were already asked:
    1) Why do you want to show another Form from within the Thread? (normally all GUI-stuff remains in the Main-Thread)
    2) Does your Thread-Functionality has to reside in a Dll - and why?
    3) What exactly *is* this Thread-Functionality (why use Threading at all)?

    In other words - simply try to clearly explain your intent - and I'm sure you will
    get help from the other participants in this thread.

    From what I can only vaguely guess, I gathered that:

    It *seems* that you will insist on showing a Form from within another Thread...

    And although this is questionable, you also seem to want to share another
    "predefined Set of Controls, a GUI-Control-Definition" from within your "ThreadForm"
    (also being able, to use that same set of Control-Definitions from within your normal MainThread).

    And there's a "Class-Type" for it in VB, -> a simple UserControl.

    When you develop such a UserControl (with your "predefined ControlSet")
    in e.g. an OCX-Project - and then compile it to an OCX, then you can use
    and instantiate this Set of arranged Sub-Controls in both, the MainThread-Forms -
    and your "threaded Forms" without "repeating yourself" (code- and definition-wise).

    Edit: in addition such a "UserControl-based Form-Replacement" (in case you
    dynamically load it onto an otherwise nearly empty TopLevelForm) - may even
    contain Menu-Definitions (within the UserControl-Project), which will then
    automatically "negotiated" and visualized in the hosting TopLevel-Form.

    Olaf
    Last edited by Schmidt; Feb 6th, 2016 at 11:01 AM.

  4. #84

  5. #85

  6. #86

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Trick and Schmidt,

    In vc++ 6.0 using MFC when we declare

    g_mydialog as global dialog object in main thread as follows

    CMyDialog g_mydialog;//CMyDialog class derived from CDialog for dialog (similar to VB6 form)

    and call g_mydialog.DoModal( ) object in new thread

    the Modal dialog gets displayed in new thread using its own message loop in new thread without depending on main thread's messageloop even though the object was created in main thread.
    This is what I showed in UniversalThreading.zip.In MFC when we go thru MFC source we understand that we can pass objects between threads some things to work and pass window handles between threads some things to work.
    The MFC framework uses WH_CBT hooks internally in the source code to achieve the above message loop affect.

    The same does'nt work in vb6 since a form object created in one thread runs only in the main thread
    using its message loop.It cannot run in another new thread using the same thread's messageloop even though it is displayed in the new thread by using either objptr or marshalling.

    The same functionality I wanted to achieve in VB6 by modifying
    GenericMultithreader application which uses CallByName for executing the threading function.
    I have sent GenericMultithreader(MThreadVB) from planet source code as attachment long back.
    It calculates primes in a dll in new thread,but it was displaying main application form in the dll in new
    thread using marshalling which indirectly makes the form run in the main thread only.
    So when we display form like this modally it was blocking main thread.So you gave me solution
    of using timer or postmessage without blocking main thread.But then also the form is displayed using
    main thread's message loop.

    You have sent me TestMT.zip which simulates the same by creating the same form2 in new thread
    entirely and copying the main thread created form2 object's data to this new local form2 object.
    But when we wanted to simulate the same in a dll in new thread, the dll won't be having any idea about
    form2 of main application and so it cannot replicate or create new form2 in the thread to display it
    since it does not contain form2 in the dll project.Again if we use marshalling it will have the same effect of running
    the form2 in main application.Inspite of all these reasons I asked for a method of injecting a dll in the main application itself since the application has form2 and let the injected dll call form directly in a new thread.For this you told you will be sending pseudo project of vtable when you get time which is a feasible solution


    Schmidt's solution anyway depends on threadlib dll for starting thread and the dll takes and gives data to main
    application(MyApp) using shared memory.But as he told it may not support objects now.

    This is explanation behind this post which i can sincerely give to both of you ie,Trick and Schmidt.

    sincerely
    Jsvenu

  7. #87
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,250

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Quote Originally Posted by jsvenu View Post
    But when we wanted to simulate the same in a dll in new thread, the dll won't be having any idea about
    form2 of main application and so it cannot replicate or create new form2 in the thread to display it
    since it does not contain form2 in the dll project.
    Just use shared interface.

  8. #88

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Trick,

    My internet connection was a bit slow so I could sent you only a private message three hours back regarding using shared interface.You can clarify me whether my assumption about shared interfaces was correct.

  9. #89

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Quote Originally Posted by jsvenu View Post
    Dear Trick,

    My internet connection was a bit slow so I could sent you only a private message three hours back regarding using shared interface.You can clarify me whether my assumption about shared interfaces was correct.
    For class public methods i could access their vtable with H1C offset as specified in Classvtable.zip but the same does'nt hold for forms as in Formvtable.zip.I can use callbyname option 1 but it is told callbyname consumes more resources.So can I use option2 with forms vtable through shared resources.Please clarify with code.

  10. #90

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Trick,
    I am sending you class_callback_test.zip which works for calling class public methods.
    Here we use objptr(c) where c is the class module object.It works for classes.
    But when I use the same for similar public form methods by replacing all objptr(c) with objptr(Me)
    the code is not working for form methods.This I wanted to use in dll using shared interface for
    calling form methods by pointers ie., thru vtable.Please clarify where I am missing
    .
    Attached Files Attached Files

  11. #91
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,050

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Can only renew my offer to help with resolving the problems in your threading-scenario,
    (without hacking around on VTables and stuff), when you'd simply answer the
    questions which were already asked - the main-question still being:

    Why do you do it in that over-complicated way - what do you really want to accomplish?

    ...and please don't answer again, "to mimick what the C++ code does" - because
    the C++ code doesn't really do anything of value - and is not well-written - so
    there's absolutely no need to attempt to port it to VB6 1:1.

    In VB6 there's different methods available, to accomplish what you're really after -
    we just still don't know what that is...

    Olaf

  12. #92

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear trick,
    When we display a new form passed from main thread using its method Show as frm.Show vbModal in a new thread started thru vbCreateThread as you showed in testMT.zip example, the main form is blocked until the new form is displayed and we can work with main form of main thread only when new form is closed.
    But when I place the following code using win32 api instead of Show vbModal the main form also works along with new form displayed.

    code
    ShowWindow frm.hWnd,SW_SHOW''frm is the new form sent from main thread using vbcreatethread
    'do something in new thread like wait or put loop so that the new thread is not terminated for example the code below
    while true
    wend


    Using the above code the main form works even when we have new form displayed in new thread.

    Why is this difference when we use frm.Show vbModal then main form blocked but when we use win 32 api ShowWindow api as above in the thread the main form is not blocked.Please clarify

    regards,
    jsvenu

  13. #93

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Post Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear trick,
    When we display a new form passed from main thread using its method Show as frm.Show vbModal in a new thread started thru vbCreateThread as you showed in testMT.zip example, the main form is blocked until the new form is displayed and we can work with main form of main thread only when new form is closed.
    But when I place the following code using win32 api instead of Show vbModal the main form also works along with new form displayed.

    code
    ShowWindow frm.hWnd,SW_SHOW''frm is the new form sent from main thread using vbcreatethread
    'do something in new thread like wait or put loop so that the new thread is not terminated for example the code below
    while true
    wend


    Using the above code the main form works even when we have new form displayed in new thread.

    Why is this difference when we use frm.Show vbModal then main form blocked but when we use win 32 api ShowWindow api as above in the thread the main form is not blocked.Please clarify

    regards,
    jsvenu

  14. #94
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,250

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    jsvenu, i created the new module.
    You shouldn't pass a reference to a VB object between threads without marshaling. You can create a form in the new thread and call the methods directly only from that thread. If you want to call a method from other one you should use marshaling.
    I suppose your thread is blocked because you call that function in the IDE (during debugging time). All functions work in the main thread in IDE. You can compile and see all works correctly.

  15. #95

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Trick,
    I agree for what you said.
    But please clarify me what is the internal win32 api code for frm.Show vbModal.
    Is the internal code for it is following

    ShowWindow frm.hWnd,SW_SHOW''frm is the new form sent from main thread using vbcreatethread
    'msg loop
    while GetMessage msg,...
    TranslateMessage msg
    DispatchMessage msg
    wend

    If it is same then the first code blocks main form and if we use the internal code it doesn't block the main form.
    This question I am asking because I tried to check local input state using AttachThreadInput api by sending false for the last parameter.But no use.

    If the above internal code is not same as frm.Show vbModal then please let me know what is the internal win32 api code of frm.Show vbModal and how to view it.

    regards,
    jsvenu

  16. #96

  17. #97

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear trick,
    As we have understanding of win32 api programming we can see that and understand it.But if we have some code how to view the internal code as we do in MFC vc++ programming by stepping thru the internal win32 code.Are there any tools or thru IDE itself can we view or extract internal code for vb6 so that we can understand it better.Please clarify.

    regards,
    jsvenu

  18. #98

  19. #99

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear trick,
    Thankyou.

    regards,
    jsvenu

  20. #100

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Trick,

    As you said in order to to use an object in the different threads without marshalling you should create a pseudo-object using a standard module. You should use the functions as the object methods, and an UDT as object data where the first Long-value implies a pointer to the functions table.

    Can you explain me what is this UDT with vtable and how it works accross different threads without marshalling as is the case of vb forms.It will be nice if you can provide me a simple vb6 working example and Can a vb form be stored in this UDT.How is this object different from normal form object.

    regards,
    Jsvenu

  21. #101

  22. #102

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Trick,
    please clear your private message inbox as I am unable to send you private message as your inbox is full.

    regards.
    JSVenu

  23. #103

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Trick,
    please clear your private message inbox as I am unable to send you private message as your inbox is full.

    regards.
    JSVenu

  24. #104

  25. #105

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Thankyou

  26. #106

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Trick,
    please clear your private message inbox as I am unable to send you private message as your inbox is full.

    regards.
    JSVenu

  27. #107

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Trick,
    please clear your private message inbox as I am unable to send you private message as your inbox is full.

    regards.
    JSVenu

  28. #108

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Trick,

    I am sending activex dll vbactthdll in which we initialize runtime thru class1.

    class1 also has a function CreateThreadfunc. The code for class1 is as follows:


    Sub Class_initialize()
    modMultiThreading.Initialize
    End Sub
    Sub CreateThreadfunc(ByVal pfn As Long)
    modMultiThreading.CreateThread ByVal 0&, 0, pfn, ByVal 0&, 0, 0
    End Sub
    Sub Class_Terminate()
    modMultiThreading.Uninitialize
    End Sub


    When I call CreateThreadfunc by adding the above activex dll in standard exe in which the code is

    Public x As New vbactthdll.Class1

    Private Sub Command1_Click()
    x.CreateThreadfunc AddressOf abc
    End Sub

    Here abc is module function defined in module.


    when I click Form1 command1 button by running the vbactexe app outside IDE it crashes instead of
    displaying form2.

    Link containing both exe and activex dll is https://www.sendspace.com/file/g6xbur

    Please clarify and correct me thru private inbox message after clearing your private inbox as it is full.

    regards,
    JSVenu

  29. #109

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Quote Originally Posted by The trick
    Dear Trick,
    Please make space in your private messages inbox space as it is full and I am unable to send message.
    I have gone thru the image and reached upto the following in CPU mainthread window

    0040116C > $ 68 D4124000 PUSH Project1.004012D4
    00401171 E8 EEFFFFFF CALL <JMP.&MSVBVM60.#100>


    When I tried search for vbdllgetclassobject in enter expression to search window I am not able to find it.i am getting unknown identifier in red colour.Am I missing some steps in execution.Please clarify

    regards,
    JSVenu

  30. #110

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Quote Originally Posted by The trick
    Dear Trick,
    Please make space in your private messages inbox space as it is full and I am unable to send message.
    I have gone thru the image and reached upto the following in CPU mainthread window

    0040116C > $ 68 D4124000 PUSH Project1.004012D4
    00401171 E8 EEFFFFFF CALL <JMP.&MSVBVM60.#100>


    When I tried search for vbdllgetclassobject in enter expression to search window I am not able to find it.i am getting unknown identifier in red colour.Am I missing some steps in execution.Please clarify

    regards,
    JSVenu

  31. #111
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,250

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Just enabling telepathy, probably you have the version which is the case-sensitive one.
    The other thing, this isn't VB-related question rather the Olly one, by viewing the basic tutorials you can see how to go to the specified symbol.
    Why do you need to debug the app in Olly? I made the framework with the detailed description which allows to work with MT in IDE and if you never ever used Olly and Asm you certainly could use it.

  32. #112

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear trick,
    I have sent a email to you just now as your private inbox is full .Please clear the private messages inbox as I am unable to send message.
    Please clarify my mail already sent.

    regards,
    JSVenu

  33. #113

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear trick,
    I have sent a email to you just now as your private inbox is full .Please clear the private messages inbox as I am unable to send message.
    Please clarify my mail already sent.

    regards,
    JSVenu

  34. #114

  35. #115

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear trick,
    Thankyou for clearing the PM box.
    I have sent a pm regarding msvbvm60.dll.
    Please clarify .

    regards,
    JSVenu

  36. #116

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Trick,
    Please clear the private messages inbox as I am unable to send message.
    Thankyou for the reply.You clarify me one thing regarding activex dlls.

    Suppose we define a class in activex say class1 which has function say classfunc1.
    Suppose the same activex dll is also exporting exportfunc1.Now if we want to use both
    in an exe application is it possible.for using classfunc1 we add activex dll thru project preferences.But how to use exportfunc1.Should we use explicit or implicit loading ie loadlibrary/getprocaddress or directly using declare.Please show small example.

    regards,
    JSVenu

  37. #117

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    Re: Displaying a form using Graphicsdll.vbp with testGraphicsdll.vbp(Code from The Tr

    Dear Trick,
    Please clear the private messages inbox as I am unable to send message.
    Thankyou for the reply.You clarify me one thing regarding activex dlls.

    Suppose we define a class in activex say class1 which has function say classfunc1.
    Suppose the same activex dll is also exporting exportfunc1.Now if we want to use both
    in an exe application is it possible.for using classfunc1 we add activex dll thru project preferences.But how to use exportfunc1.Should we use explicit or implicit loading ie loadlibrary/getprocaddress or directly using declare.Please show small example.

    regards,
    JSVenu

  38. #118

  39. #119

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    77

    sub: activexdll classfunc and exported function

    "Why do you need to export a function if you already have exported the class? Just call the method.
    Please, create a thread with your question."

    Dear Trick,


    Thankyou for the above reply.

    I have asked the question regarding activexdll classfunc and exported function because I observed that

    1.When I create thread in a module callback function and display a modal form by clicking on commandbutton1 .Immediately it appears.Again immediately if you click on the same button it appears again immediately.This you can repeat and see any number of times by clicking the same button.It works perfect.

    2.But when I create thread in a classmodule callback function and display a modal form by clicking on commandbutton2 .Immediately it appears.Again immediately if you click on the same button it does not appear until we close old form even though they are being created in new thread each.Why? How to make then work as in case 1. like in module callback function.
    Please clarify
    .Here module callback and class callback are analogous to exported func and classfunc in activex dl and here exported funcwork performs perfect compared to classfunc.Why.Please clarify.(I have already send a a private message also)

    The complete code link is https://www.sendspace.com/file/ni7bh8


    regards,
    JSVenu

  40. #120
    Addicted Member
    Join Date
    Aug 2016
    Posts
    143

    Re: sub: activexdll classfunc and exported function

    Why you keep posting on this thread?
    Please, create a thread with your question.

Page 3 of 4 FirstFirst 1234 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
  •  



Featured


Click Here to Expand Forum to Full Width