How to mark / build C# / WPF component STA

I am hosting WPF components in unmanaged MFC. This WPF components will
do some ricktext editing. Hosting / editing are working fine but
closing will crash application on exit (release version only and no
crash on debug). The following is the current structure:

class parentA_COM : definited / implemented in unmanaged C++, STA
class memberB_COM : definited in unmanaged C++, but implemented in C#
(ComVisible)
class winUserControl: implemented in C# to host WPF user control;
class wpfUserControl: implemented in C#

class MyApp // unmanaged C++
{
  main ()
  {
    parentA_COM pPA();  // Initialize COM component
  }
}

class parentA_COM // unmanaged C++
{
  void get_hWnd()
  {
    m_ipMB.CreateInstance(xxx);
    m_ipMB->get_hWnd();
  }

private:
  memberB_COM m_ipMB;
}

class memberB_COM : IDisposable, ...  // C#
{
  constuctor // initialize winUserControl
}

class winUserControl : UserControl
{
  host WPF control wpfUserControl
}

How can I mark / make wpfUserControl / or winUserControl / or
memberB_COM STA? Thanks.
0
Leo
12/29/2009 9:22:33 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

3 Replies
1004 Views

Similar Articles

[PageSpeed] 26

Leo wrote:
> [...]
> How can I mark / make wpfUserControl / or winUserControl / or
> memberB_COM STA? Thanks.

Your question is not very easy to understand.  There's not even any C# 
code, and the C++ code won't compile.

As far as marking COM classes, you can indicate when registering the 
class whether it's MTA or STA.  If you don't indicate, it's assumed to 
be STA.

Now, when _using_ an STA COM object, you also need to make sure you 
create it in an STA thread.  But that's not what you asked about.

Pete
0
Peter
12/29/2009 10:12:47 PM
Pete,

First apologize for posting same thing on multiple forums. I don't
know how to make it cross forum. If so, definitely I will only post to
one.

Second thanks for your reply. What I am trying to do is to mark and
build the WPF component as STA. I couldn't find instruction on how to
do so (VS 2008 C# project) although I do see option for C++. If you
know, please advise how.

Thanks again...

Leo
0
Leo
12/30/2009 4:59:00 AM
Leo wrote:
> Pete,
> 
> First apologize for posting same thing on multiple forums. I don't
> know how to make it cross forum. If so, definitely I will only post to
> one.

I'm sure if you check with Google, it can provide references that detail 
the difference between multi- and cross-posting, and how to do it 
correctly.  The short version is: write the post once, and specify all 
newsgroups in the "Newsgroup:" field, separated by commas.

> Second thanks for your reply. What I am trying to do is to mark and
> build the WPF component as STA. I couldn't find instruction on how to
> do so (VS 2008 C# project) although I do see option for C++. If you
> know, please advise how.

Please be more specific.  What "option" do you see in C++?  AFAIK, 
neither C# nor C++ has a project setting that sets STA vs MTA.  As I 
mentioned before, whether a COM object is STA or MTA has more to do with 
the implementation, which is a holistic attribute, not a single setting.

When the COM object is registered, you can specify the apartment type in 
the registry entry for the COM server.  But that's not 
language-specific.  The same registry values are set whether the COM 
object was written in C# or C++.

I don't recall, it's possible the C++ ATL project template provides the 
setting in the template wizard, but once the project is created, there's 
no setting to change, and you can easily inspect the C++ project to see 
how the setting is made.

Until you provide much more detail in your question, it's doubtful 
you're going to get a useful answer.  For best results, post a 
concise-but-complete code example showing exactly what you're trying to 
do, and what you're having trouble with at the moment.

Pete
0
Peter
12/30/2009 5:11:59 AM
Reply:

Similar Artilces:

paragraph mark appears inside paragraph
hello, i received this document for editing and it has a paragraph mark inside a paragraph. when i'm in normal or outline view, i only see one paragraph, the same if i click 3 times in the margin, but still, this paragraph mark is in the middle of the text. can anyone explain how this is possible? thanks What color is it? Is it selectable? Does it disappear like the others when you hide the non-printing characters? What about Print Layout View? The pilcrow (�) is nothing more than another symbol character which can be inserted just like any other. Perhaps that's the cas...

CRM mail router marking e-mails as read
Hello all I have a couple of questions regarding the CRM E-mail router for V3 Incoming emails into Outlook (with CRM desktop client) are getting marked as read before they actually are. Is this by design? Is so, is there a config setting somewhere that can change this behavior Andy comments or suggestions would gratefully received I assume the outlook client has the rules applied for the exchange connector. The action of sending the mail to the crm exchange sync mailbox appears to mark the email as read -- ======================= John O'Donnell Microsoft CRM MVP http://codegallery...

Need quick way to build distribution list
Hi. I need to build a distribution list quickly which has as it's members people sending me emails (people not currently in my contacts). But the emails aren't coming from the individuals, they are coming from a form on my website. So - all the emails come from the same address (my web form) - all emails are formatted the same - all contain an email address for someone who filled out the form I'd like some kind of drag and drop or automated way to "dump" all those addressed into a list so I can reply to them en masse. Anyone know of a way to do this using ...

Exchange 2003 Server Promoted to DC, Missing AD Components
Long story short, we had to promote an Exchange server to a DC when we added Citrix to our other server (2 servers in network). Because we had installed Exchange first, I think it created local accounts for all the Exchange Accounts and now they are missing in AD when it was promoted. I re-ran forestprep and domainpre and the AD is still missing the Exchange user accounts. Luckily, I have just set the server up, so there is no live data, but need to figure out how to get the AD fixed. Anyone have other suggestions? Everything else in setup appears to be correct except the user acc...

Saving & Opening excel file & worksheet with Visual C++
I writing a sw application with Visual C++ to read/write data to excel file. I have found an example @ the MSDN on how to create a new excel file (http://support.microsoft.com/?scid=kb;en-us;308407&spid=2990&sid=620) using automation method. My question is how do I save/open an excel file using automation method. Thanks, WL ...

How to write custom serialization method in C# web service
Hi, I have a C# web service client that talks to a JAVA application sever. I use AXIS to generate the WSDL file, use wsdl.exe to generate proxy stub c# code. When I try to use c# client connect to application server, I did not get the result in the C# client side, I used a soap monitor to look at the SOAP messages that were exchanged, I can see server returned a correct SOAP message, but the C# client failed to deserialize the XML result back to the C# object. I wonder if there is a way to write a custom XML deserializer to populate the result back to C# object. The serialization part seemed...

How do I add column A data labels to a scatter of columns B and C?
I have made a scatter plot using columns B and C as my x and y coordinates. I would like to use the data in column A to label my points. I already have the XY chart labeler 97 installed and selected, but I don't know how to get the data labels to show up on my graph. Thank you! Hi Christina - There are a couple of well written Excel add-ins you can download to do this: Rob Bovey's Chart Labeler, http://appspro.com John Walkenbach's Chart Tools, http://j-walk.com Both are free downloads, they install easily, and they integrate into Excel's interface very nicely. They l...

29 Books and Tutorials for DotNET, C#, VB.NET and ASP.NET
Hi here is a list of 29 Books and Tutorials for DotNET, C#, VB.NET and ASP.NET. Download fast at http://free-tech-ebooks.blogspot.com/ ...

Outlook client Visual C++ Runtime Error
Hello all: I installed MSCRM v4 today and then ran the v4 upgrade on the client machine (only 1 user). All seemed well but now the user is getting an error, she gets a message box that says: Microsoft Visual C++ RunTime Library Runtime Error! Program C:\Progra~!\Micros~1\Office11\Outlook.exe Abnormal program termination Has anyone seen this before and know how to fix it? Thanks! John This error occurs when a contact is being synchronized with a birthdate prior to januari 1, 1970. There is a hotfix available: http://support.microsoft.com/default.aspx?scid=kb;EN-US;948045 -- Patric...

Picklist shows number inreport building
Hi When i tried to create report using vs.net business intelligense report building everthig going fine. but my picklist field in cm displayed number(index) rather than the data of the picklist. How can i changr the picklist index to data in crm reports Please help me sujith Hi Sujit, The picklists values are stored in a table called StringMapCRM You can directly link to it or if you use the CRM views (ie: FilteredAccount or Account) instead of the CRM tables (ie: AccountBase), you will have the picklist values already linked. Actually, I found out the easiest way to see which join to ...

It is a question about the Visual C++ 6.0 Enter(or Pro)
Hello. Environment : Visual C++ 6.0 Enter versions When I add approximately 1,500 sources to one DLL and build. vc60.idb becomes around 35MB, and the following errors are displayed, and build stops. \x1.cpp(19) fatal error C1073: Internal error involving incremental compilation(compiler file 'main.c', line 629) \x1.cpp(23) fatal error C1073: Internal error involving incremental compilation(compiler file 'main.c', line 629) When I delete vc60.idb, An error is not displayed, and build is performed till the last. Thanks, "teratera" <teratera@discussions.m...

Y-axis tick marks
Hi all, I'm pretty knew to Excel VBA and charting. I have a simple histogram chart on a worksheet and the data ranges are 1 to 100. So Excel automatically puts the Y-axis tick marks at 0, 20, 40, 60, 80, 100. But I only want three tick marks to show on the Y-axis (0, 50, 100). How can I do that? Also is there a way to put a horizontal line at the 50 y-axis tick mark that will show on top of my chart? My users want to be able to quickly see the 50 line (i.e. which histogram bars extend above it, and which ones don't reach it). It would be great if I could programmaticall...

How to save color images in C-M-Y-K format???
I prepare newspaper advertisements for my small company using Publisher. Although the graphics I use appear in color on my monitor, and the newspaper tells me that they appear in color on their monitors, too, when they are finally printed in the newspaper they only come out in grayscale or black and white. The paper tells me that this has to do with the way I save my creative work, that I need to be saving it in C-M-Y-K color format and not whatever the other color format is (which apparently is the default format used by Publisher?). I have no idea how to change the format default ...

Restoring from an OST after re-build new Exch2003
The original Exchanger server was gone during disaster. So a new one was rebuild from scratch with the same Wins/DNS/Domain name. Identically users name were also created w/ new set of pwd. The outlook 2003 clients had been using OST before and after the disaster. But now, the new server is connected. OL Exch Client Profile was re-created. Only at that point, we reliazed the OST file was not accessible anymore. All the old email is gone now. One thing we did before re-connect to the new server was to copy the entire directory C:\Documents and Settings\User1\Application Data\Microsoft\Outlo...

ANN: C# Online.NET Summer 06 Contest
FOR IMMEDIATE RELEASE C# Online.NET Summer 06 Contest Apress and C# Online.NET have joined forces to reward the most prolific contributors to C# Online.NET. Our contributors are all volunteers from around the Globe: They write articles, source code, and tutorials for the benefit of the C# and ..NET communities. They manage to combine giving back with personal growth. And, we all benefit from their labors of love. Apress is making it possible to reward their, essentially, selfless contributions by donating 5 Grand Prizes. They will be welcome additions to any C# or .NET developer�s library....

Looping through table to build sql case statement
Hi, I have the following sample table. cust_num slsman site sales_ytd c000200 904 11199 1023.1 c000200 904 11121 2000.12 c000201 927 11199 325.12 c000201 927 11121 245.5 Also I have the following site table prototype Site 11199 11121 The output of the select statement should be like the following: cust_num slsman 11199_sales_ytd 11121_sales_ytd c000200 904 1023.1 2000.12 c000201 927 325.12 245.5 This has been achieved through hardcoding the following. The results are exactly as I would like above select cust_num,slsman, SUM(CASE WHEN [site] = ...

Interface between AOL instant messenger and Visual C++.
A client has asked for a feature where I would monitor AOL instant messenger messages and act upon information received in the messages. I would have one access point and I would need to monitor several IM accounts. I would write my program in Visual C++ version 6. Is there an interface or API? How would I connect? How about this: http://dev.aol.com/aim Download page: http://dev.aol.com/aim/downloads AliR. "TonyG" <TonyG@junk.com> wrote in message news:urjmk.17529$mh5.11400@nlpi067.nbdc.sbc.com... >A client has asked for a feature where I would monitor AOL instant ...

Disable formatting marks in Outlook 2002
Would greatly appreciate advice for the following...composed emails now contain the paragraph mark and I would like to eliminate that. Can anyone instruct me how to do this? Thanks in advance, Deb trillium <dmphilippi@yahoo.com> wrote: > Would greatly appreciate advice for the following...composed emails > now contain the paragraph mark and I would like to eliminate that. Can > anyone instruct me how to do this? Since formatting marks appear only when you're using Word to compose your mail, this is a Word, not an Outlook question. Click Tools>Options>View and u...

Building Dynamic Case Statement
Hi All can any body help me for the following logic. Input ------- a,b output --------- case when isnull(a,0)=0 then b else a end Input ------- a,b,c output --------- case when isnull(a,0)=0 then (case when isnull(b,0)=0 then c else b end) else a end Input ------- a,b,c,d output --------- case when isnull(a,0)=0 then (case when isnull(b,0)=0 then (case when isnull(c,0)=0 then d else c end) else b end) else a end and so on..i can give input a comma separated string earlier help is highly appreciated. Regards Kalyan kalyan (kalikoi@gmail.com) wr...

Clients showing Yellow Triangle marks
We have WSUS server one Upstream Server and 5 Downstream Server in the console clients not showing 100% complete satus it showing 99%,98% like this when we check the client machine we can see all approved patches are installed successfully .Please Suggest for this WSUS newsgroup: http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.windows.server.update_services via NNTP: news://msnews.microsoft.com/microsoft.public.windows.server.update_services WSUS-specific forum: http://social.technet.microsoft.com/Forums/en-US/winserverwsus/thread...

Saving data to SQL from unmanaged C++ using XML/webservice
I have a Webservice written in C# that provides data to both a web browser through ASP.net and to a VC++ client. I have been able to retrieve data from SQLServer and passing to my unmanaged C++ client as XML without a problem using the SqlDataAdaptor and the DataSet. I am a bit confused how to construct the XML to pass to the Webservice to save data to SQL Server from my VC++ unmanaged client. the client VC++ code: HRESULT CStaffAccess::Save(CStff* pStaff) { CString strXML CreateXML(pStaff); BSTR bstrXMLString = strXML.AllocSysString(); BSTR bstrResult; STMWebService...

Task manager in C#
How to create task manager which shows process description and CPU columns like in windows Task Manager? I looked into Process class but it does not have Task Maanger CPU and process description column properties. Also it returns lot of duplicate process names as "svchost" . How to explore from C# code what is really running instead of svchost generic name ? Andrus. Andrus wrote: > How to create task manager which shows process description and CPU > columns like > in windows Task Manager? > > I looked into Process class but it does not have ...

Extend the XML Schema via C# objects
I have C# objects/entities (like person or customer) which contains the usual amount properties/attributes like name, address and so on.. I would like to "tag" some of these properties, so that when I'm generating and XML Schema (via Wsdl for instance) the tags are displayed in the Schema portion of the Wsdl. Something like the following snippet: <?xml version="1.0" encoding="utf-8"?> <xs:scheme attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" ...

Part Revisions A, B, C
Hello, I was hoping to find out how everyone out there keeps track of Manufacture parts with different revisions ?? When a part gets a design change to you give is a completly new number in GP and track this invenotry, or do you use the ECN function to track this ? Regards, Scott Scott, The guideline for whether a design change warrants a new item number is this - Fit, Form, Function If the Fit, Form, and Function of the item stays the same, then the item number stays the same and the design change is tracked via revision number (i.e. ECN). If any one of those three characteristics c...

OnTimer() Not Being Called after timer is set up (VS C++ 6.0)
OK, here is what I have done. I am looking to use a timer to complete some refresh operations every 2 seconds. However, I cannot get my OnTimer()function to be called. I set up a timer with the following line of code: SetTimer(1, 2000, 0); Then, I have the Ontimer function, which I created from ClassWizard as a message handler for WM_TIMER. void CProbeTalkMenu::OnTimer(UINT nIDEvent) { m_szStatus += "*"; UpdateData(); CDialog::OnTimer(nIDEvent); } OnTimer() is never called. I am afraid that I am failing to do something grossly important. Can anyone explai...