November 15th, 2003, 12:20 PM
problem with multiple use of the same COleControl
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
<do sth on global resources(to draw sth)>
When use many instances of it in mysecond project
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
November 15th, 2003, 06:55 PM
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.
November 16th, 2003, 06:05 AM
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 )
November 16th, 2003, 03:36 PM
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.
November 16th, 2003, 05:02 PM
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)
<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.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!