Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 523429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:27:41+00:00 2026-05-13T08:27:41+00:00

I have a .NET application containing a WinForm. This WinForm contains an unmanaged ActiveX

  • 0

I have a .NET application containing a WinForm. This WinForm contains an unmanaged ActiveX control and a few other controls. This application works fine in standalone mode. Now we want to publish some kind of interface so this Winform can be used from unmanaged C++/MFC applications using Interop functionality. The client applications will Show this form in a modeless manner. When the user inputs the details the same are passed to the client using COM event source/sink (or connection point) method.

I have followed various articles and one of the method that works for us is
http://codebetter.com/blogs/peter.van.ooijen/archive/2005/06/03/64041.aspx

But if I start more than one thread from the same client application, the second instance of form throws access violation exceptions because the ActiveX control on the form expects the thread to always be a UI thread (based on my observation).

Could you tell me what is the right way to expose a WinForm functionality to unmanaged client applications via Interop?

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:27:41+00:00Added an answer on May 13, 2026 at 8:27 am

    The article you linked gives you all the info you need to properly host a Form in an unmanaged app. You should look for the source of the AV elsewhere. Get that started by using the debugger. You can force it to stop on the exception with the Debug + Exceptions dialog, Thrown checkbox.

    The STA requirement is almost always sufficient to keep an ActiveX control operating properly in a multi-threaded application. It provides the guarantee that all method calls are made on the exact same thread in which the coclass was created. In other words, any instance variables inside the coclass implementation are guaranteed to be used in a thread-safe manner.

    One guarantee you don’t have here though is whether the control properly handles global state. Instance variables are safe, global variables are not when you use the control in different threads. A possible workaround for that is to use only one thread instead of one STA thread for each form instance. That’s a bit tricky, you’ll need an invisible helper form that manages the thread. Keeping it alive and creating new form instances through its Invoke() method.

    Before you go there, find out what’s crashing first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .NET application that contains a checkbox (System.Windows.Forms.Checkbox). This component (WindowsForms10.BUTTON.app.0.378734a1) is
I have an asp.net application containing pages that lie in multiple folder. I have
I have a Asp.net MVC web application, containing mostly text. I want to put
I have a .NET application which serializes an object in binary format. this object
I have developed an asp.net web application containing 40-50 pages. I have implemented logger
I have problem in parsing XML containing gsm packets through my .Net application.I want
I'm working on an asp.net application. I have a Domain assembly (containing mostly command
I'm working on an asp.net application. I have a Domain assembly (containing mostly command
I have a Solution which contains an ASP.NET Web Application project. Web Application project
Asp.Net 2.0 framewrok - VB.Net application I have a UserControl containing a Asp.Net DropDownList.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.