By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,956 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,956 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.