Problem on using 2nd activex control created dynamically...

F

fumihiko

Hi,

I created an activex control (C++), and it uses another COM dll (C++).
This COM dll links with a static library that dose some calculation.
(both are debug multithreaded dll)

I created a C# client having activex control embedded at the very
beginning (added in the design window); then, I created another same
activex control at the runtime. After the 2nd activex control is
created, I start to get errors on the function calls to the static
library in the COM dll.

Can anyone help me solve this problem? Or give me some suggestion?

I have tried to have two activex controls (added in the design window)
and there is no problem accessing the functions in the library in the
another COM dll; also, I have tried to use QueueUserWorkItem to fire an
event back to the main thread and create the 2nd activex control. Both
approachs do not work.

Thanks

Fumihiko
 
N

Nicholas Paldino [.NET/C# MVP]

Fumihiko,

You mentioned that you are using QueueUserWorkItem to fire an event back
to the main thread, which indicates to me that you are trying to create the
control on another thread. Calling QueueUserWorkItem will not ensure that
the delegate is called on the UI thread.

Rather, you need to make sure that your control is created on the UI
thread. You can do this by calling the Invoke method on the form that the
control will be embedded on. This will cause the delegate passed to it to
be called on the UI thread. This is how you should notify the main thread
to create the control.

If a control is not created on the UI thread, then you will run into
errors like this, especially COM objects.

Hope this helps.
 
F

fumihiko

Thanks for your help :)

I am still not clear what I should do to avoid this problem.

Do you mean that ... since the first activex control embedded in the C#
design dialog (created in the function InitializeComponent()) is
created in UI thread, I have to create the 2nd control in UI thread,
too !? And by using the Invoke mothod on the form, the UI thread will
create the 2nd control, and later, both controls can access the static
library functions in the same COM instance.

I will try it later tonight, and see if it works.

Thanks,

Fumihiko
 
F

fumihiko

Tried last night, but still did not work.
I also try to build both controls in the runtime using the "invoke",
and then discovered that both controls cannot access the dll functions
in the COM object.

I am wondering... what's the differences between a control that built
in design dialog and built in the runtime? How come the control that
built in the design dialog can successfully use the dll function in the
COM object, but the control built in runtime got an error?

Thanks,

Fumihiko
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top