Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I imported the MSComm ActiveX from VB6 to create a modem object. But C# generates folowing error message when the test program is run. (no compiler warnings)

An unhandled exception of type 'System.Threading.ThreadStateException' occurred in system.windows.forms.dll

Additional information: Could not instantiate ActiveX control '648a5600-2c6e-101b-82b6-000000000014' because the current thread is not in a single-threaded apartment.

 

First time I hear about single-threaded apartment, anyone knows what I can do to solve this? Or some general background information...

Edited by PlausiblyDamp
qrt
Posted

Might it be that this has something to do with the project type that I started?

 

I just wan't to make a class that I can use in other projects, so I started a ClassLibrary-project in C#. (Visual Studio .NET 2000). I had to add a windows form in the project however, that just acts as a container for the MSComm32.ocx ActiveX. In the Modem class, I then wanted to create a variable of the type AxMSCommLib.AxMSComm and to instantiate that variable by giving a reference to the ActiveX object on the container form. This is necessary because if you only make a variable of that type and instantiate it by running the constructor (New AxMSCommLib.AxMSComm()) the code seems to work, but the control will not be installed/registered on the target machines where the application will run on. By putting it on a form, just like in VB6, Microsoft seems to give a free runtime license to the installing machine.

 

I recently stepped from VB.NET to C#. In VB.NET I have done this trick before. I just wonder if C# has a problem with that specific ActiveX, or if I maybe should change the project type. Maybe ClassLibrary project should never contain Windows Forms?

qrt
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...