CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2003
    Location
    Poland
    Posts
    22

    problem with multiple use of the same COleControl

    Hi

    I have the following problem: There is a class MyControl derived from COleControl (which then I want to use in another project )
    which has implemented
    void func1()
    {
    <do sth on global resources(to draw sth)>
    }

    When use many instances of it in mysecond project

    for(int i=1;i<10;i++)
    {
    MyControlTab[i].func1()
    }
    at the same time func1 is beeing called from several controls making acces violation. I was trying to use waiting loops (with Sleep) in func1 or in the "for loop" but all in vain.
    But when I put in the "for loop" AfxMessageBox -so main program is waiting for user resond while current control from the loop can end func1 separatelly everythings works good -
    -so I guess it's a problem of COleCotroll message dispatching scheme.

    Can any give me a piece of advice or give me a link concerning his subject



    Thanks in advance
    dj

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    You can't just derive classes and expect them to be available.

    It's like saying "Hey I want a class but im not going to tell anyone about where it is".

    You need to :

    (1) Create a COM dll (create an ATL project).
    (2) Add all your classes and members to this.

    You need to read up on COM and understand it.

    Darwen.

  3. #3
    Join Date
    Mar 2003
    Location
    Poland
    Posts
    22
    This ATL project is ready (it was made and tested by another person) and works OK when one instance of control is beeing used (as an ActiveX in another project). So it's not a problem, how to make such a project.

    Now, I have to make it working in situation of multiple use, and I have problem in synchronizing it (to avoid multiple acces to global resource)


    In my example places above, in the loop from main program, all conrols seem to have called their func1() at the same momemnt after the end of the loop (are the oles separete thread waiting until the thread of the main programm ends end then executing).

    When in my ATL project (with declaration of my control) I am trying to put some wainting mechanism it hangs up(the control represents a window, func1 calls OnDraw, I've somewhere that OleCtrl have to serve it's drawing events without a break - is it true?)



    (sorry for bad english )

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    I don't understand why you need to synchronise anything.

    COM operates on an instance basis : every control will have its own instance, and shouldn't have any shared resources.

    You don't just have 1 COM object which persists throughout the application : you have many COM objects (one for each call to CoCreateInstance).

    It seriously sounds like there's a problem with your control and not a problem with COM.

    Without knowing more about the implementation of your COM object I can't really help any further.

    Darwen.

  5. #5
    Join Date
    Mar 2003
    Location
    Poland
    Posts
    22
    Yes, I understand that it's not a problem of COM but MyControl implentation.


    This class represents a window in which in implementation of OnDraw method I have to use global functions (of a library used in MyControl project, which has to be used here)
    MyControl::OnDraw()
    {
    <rapainting using global functions and data>
    }


    And in my main project I am creating several instance of it. When OnDraw methods are beeing called I'll have access violations. So I want to force MyControl::OnDraw() calls to be executed separatelly.

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