CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2001
    Posts
    1

    Handling free-threaded callbacks in VB

    I have a free-threaded component, written in C++, which waits on RS232 I/O and does a callback when reading or writing data.

    In VB, I have created a Class Module with "Implements xxxLib.Icallback". This callback works successfully when working with local or global data; so, for example, you can store received data in an array. BUT VB crashes when trying to write to a CONTROL on a form.

    In the Win32 API, you would be using PostMessage to send the data across thread boundaries when your callback was received. In VB, I assume that VB is treating the controls as ActiveX objects and it doesn't like talking to an apartment-threaded ActiveX object while in a callback from a free-threaded component. But this doesn't solve my problem...

    At the moment, I have the truly dreadful "solution" of saving callback data in an array and polling with a timer in my main form. There must be a better way, surely....


  2. #2
    Join Date
    Jul 2000
    Location
    Hawaii
    Posts
    281

    Re: Handling free-threaded callbacks in VB

    I am failing to see how

    "BUT VB crashes when trying to write to a CONTROL on a form."

    affects the call back from the server object.


    It sounds like you are attempting to communicate with third party software rather than handling the callback in your own code (and then passing this information to the control from your form class or other base program over which you have source code control)



  3. #3
    Join Date
    Apr 2000
    Posts
    737

    Re: Handling free-threaded callbacks in VB

    As you expected, VB doesn't like free thread very well. your problem will be solved if you can setup the free-thread component to become apartment thread and marshal the object from the apartment thread to your free thread.... but overhead will be quite large for callback..

    you might want to try this, compile this program in VB5, I bet it will run.....

    In VB 6, by calling other thread component in the free thread will cause a system error in vb6 runtime.

    I have create a class to capture network packet. I create extra thread for backgroud packet capturing.. then when there is a packet, I need to call one of the method of main class to notify the client... so, you can see here, that I do create a free thread and, yes call the method of the component in apartment thread.. but the catch is, you must setup the free thread to become apartment thread & marshal the component.






    HTH

    cksiow
    http://vblib.virtualave.net - share our codes

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

Featured