473,394 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

VC++ 2005 problem creating an ActiveX in a secondary Thread

Hi all,

In my vc++ 2005 dialog based application i need to use a comunication
activex component in a secondary thread:
CFINSAxEFS* pNewAx = new CFINSAxEFS();
if ( !pNewAx->Create( NULL, NULL, CRect( 0,0,0,0), pParent,
pNode->m_nFinsID) )

throw FALSE;

If i use this code in the main dialog it works fine.

If i use this code in a secondary thread, the program execution don't exit
from the pNewAx->Create function and any exception / error will be rised.

The same code compiled in VC++ 6.0 or VC++ 2003 works fine.

Someone can help me?

Thank you.

- Dany -
Oct 31 '07 #1
8 1968
Hi,

Update of my problem..

On start of the app i need to read some settings in xml file doing so:

::CoInitialize( NULL)
Read setting using msxml
::CoUninitialize();

from this point on, the creation of the activex fails.
If i create the activex before the ::CoInitialize( NULL) call it works fine,
but i need to make it after having read the settings.

The problem is the same in vc++6.0 and vc++ 2003.

Thanks.

- Dany -

"Daniele Piccinini" <da***************@nospam.nospamha scritto nel
messaggio news:Ou**************@TK2MSFTNGP05.phx.gbl...
Hi all,

In my vc++ 2005 dialog based application i need to use a comunication
activex component in a secondary thread:
CFINSAxEFS* pNewAx = new CFINSAxEFS();
if ( !pNewAx->Create( NULL, NULL, CRect( 0,0,0,0), pParent,
pNode->m_nFinsID) )

throw FALSE;

If i use this code in the main dialog it works fine.

If i use this code in a secondary thread, the program execution don't exit
from the pNewAx->Create function and any exception / error will be rised.

The same code compiled in VC++ 6.0 or VC++ 2003 works fine.

Someone can help me?

Thank you.

- Dany -


Oct 31 '07 #2
General rule you should adhere to.... only perform GUI related work in the same thread (which is typically the main thread). Worker
threads should never perform GUI functions. This is simply the way Windows was designed.

Brian

"Daniele Piccinini" <da***************@nospam.nospamwrote in message news:Ou**************@TK2MSFTNGP05.phx.gbl...
Hi all,

In my vc++ 2005 dialog based application i need to use a comunication activex component in a secondary thread:
CFINSAxEFS* pNewAx = new CFINSAxEFS();
if ( !pNewAx->Create( NULL, NULL, CRect( 0,0,0,0), pParent, pNode->m_nFinsID) )

throw FALSE;

If i use this code in the main dialog it works fine.

If i use this code in a secondary thread, the program execution don't exit from the pNewAx->Create function and any exception /
error will be rised.

The same code compiled in VC++ 6.0 or VC++ 2003 works fine.

Someone can help me?

Thank you.

- Dany -

Oct 31 '07 #3
Hi Daniele,

Thank you for the further information.

I would suspect the problem occurs because you are passing the main thread
window "pParent" as the parent of this control in second thread. This may
cause some problem. As Brian pointed out, all the windows/controls in the
same top-level window should reside in the same thread.

Then, can you tell me why do you want to place this CFINSAxEFS in the
second thread? Thanks in advanced!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 2 '07 #4
Hi Daniele,

Further discussion with other MFC experts confirms my suspicion.

Yes. It is a mistake to pass a pointer of a CWnd-derived class across a
thread boundary. Any calls across that boundary that attempt to use the
thread-local storage that MFC maintains for window objects will fail. This
is not specific to ActiveX - it is true for all window class objects in MFC.

So, why do you want to place CFINSAxEFS in the second thread?

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 5 '07 #5
Hi Jeffrey,

Thank you, and sorry if i'm late with the answer but I've had some problem.

The ActiveX is a Omron comunication tool useful ti perform serial,
ethernet... comunication with Omron Plc device.
I've placed the ActiveX control in a secondary thread so the comunication
delay don't affect the user interface.

I've tried to pass to the ActiveX a pointer to a Cwnd created in the
CWinThread but the creation of ActiveX still fails.

The strange thing is that if i create the activex in the secondary thread
before calling ::CoInitialize( NULL) in the main thread, all works fine.
If i create the activex in the main thread after calling ::CoInitialize(
NULL) function all works fine.

I start to think that this is a specific behaviour of this activex.

Thanks in advanced!

- Daniele -
Nov 6 '07 #6
Hi Daniele,

Thanks for your feedback.

The thread that creates the ActiveX control must be the same thread of its
parent window. That is all the GUI stuff must reside in the same thread. If
you did not obey this rule, this is an unsupported scenario and may result
in different strange behavior or failure.

If it is the Omron comunication tool that performs synchronous I/O
operation that blocks your GUI thread, I think this should be a bad design
of Omron.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 7 '07 #7
Thanks very much Jeffrey for your patience.

I think my scenario is compatible with your description. I try to describe
better.

The main thread, ( those that manage the GUI ) create a secondary
CWinThread.
The seconary CWinThread create the ActiveX and pass it's window as parent
window.
Note that i don't have to show the ActiveX's user interface anywhere, i only
need to call some
of it's function to read/write data from/to the devices in Sync or Asinch
mode.

Thanks.

- Daniele -
Nov 7 '07 #8

"Daniele Piccinini" <da***************@nospam.nospamwrote in message
news:et**************@TK2MSFTNGP05.phx.gbl...
Thanks very much Jeffrey for your patience.

I think my scenario is compatible with your description. I try to describe
better.

The main thread, ( those that manage the GUI ) create a secondary
CWinThread.
The seconary CWinThread create the ActiveX and pass it's window as parent
window.
Note that i don't have to show the ActiveX's user interface anywhere, i
only need to call some
of it's function to read/write data from/to the devices in Sync or Asinch
mode.
The problem is that this should be a COM component, not an ActiveX control.
With no need for a GUI, there's no need for any of the ActiveX hosting
machinery. But VB (classic VB, versions 4-6) had poor design-time support
for components, and MS set a bad example by making the MSCOMM.OCX a control
instead of a component, so apparently your vendor committed the same sin.

Take the control off your Form at design-time, and instead add it to a class
object using a WithEvents variable. Possibly if the GUI truly is optional
it can be used this way.
>
Thanks.

- Daniele -

Nov 7 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Adam Clauss | last post by:
I am creating a plugin for MS Outlook. Upon clicking a toolbar button, I create series of threads (variable number each time). Within each thread, I start a form using Application.Run(...). This...
2
by: um | last post by:
When the POSIX pthreads library for w32 release 2-2-0 (http://sources.redhat.com/pthreads-win32/) is compiled with VC++6 then it compiles and passes all the benchmark tests in the subdirectory...
10
by: Adriano Coser | last post by:
Hello. I'm moving an application VC 2003 to VC 2005 Beta2. I need to set STA ApartmentState model so the drag & drop registration can work. I used to do...
0
by: dbaechtel | last post by:
I have a VB.Net application in VS2005 that communicates to a ATL written in VC++ loaded as a project resource. The communications with the ATL DLL library work well in the VB primary thread. But if...
1
by: OfurGørn | last post by:
I am creating an ActiveX control that should contain a reference to a certain COM interface. I have written before a C# application containing this COM interface but my problem is that it seems...
1
by: Sugan | last post by:
Hi all, A VC 6.0 project( output is a Activex DLL) is converted to VC 2005 project and the output here is again a DLL. When i try to include this DLL as a refernce is another VB 2005 project,...
5
by: cory.laflin | last post by:
Hi. I have what I believe to be a very simple task I'm trying to accomplish in VC++ 2005 and I simply can't make it work. I have a good working knowledge of C, a basic-to-middling knowledge of...
15
by: Michael Tissington | last post by:
I have a Visual Basic 6.0 ActiveX Control. It seems there is no way with VS 2005 to create a similar control for containers that host ActiverX controls, is this correct ? I'm thinking of...
4
by: Gillard | last post by:
when i try to create a project from template i get an error like error : activex can t create object when i try to compile a sinple c++ project that i get from else where i get multiple error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.