471,570 Members | 966 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

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

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

Nov 17 '05 #1
3 2192
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.
--
- Nicholas Paldino [.NET/C# MVP]
- ca*******@caspershouse.com

<fu******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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

Nov 17 '05 #2
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

Nov 17 '05 #3
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

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by George Hester | last post: by
3 posts views Thread by Eric | last post: by
reply views Thread by Luis Esteban Valencia | last post: by
13 posts views Thread by Lee Newson | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.