473,756 Members | 5,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with Threading

VS 2005 / C++ / __gc program (converted from VS 2003)

i have this code in my program:

int found;
String *temp;
this->ofdOpen->ShowDialog() ;

the last line produces the folloing unhandleld exeption:
An unhandled exception of type 'System.Threadi ng.ThreadStateE xception'
occurred in System.Windows. Forms.dll

Additional information: Current thread must be set to single thread
apartment (STA) mode before OLE calls can be made. Ensure that your Main
function has STAThreadAttrib ute marked on it. This exception is only raised
if a debugger is attached to the process.
However my Main funtion lookes like this:

int APIENTRY _tWinMain(HINST ANCE hInstance, HINSTANCE hPrevInstance, LPTSTR
lpCmdLine, int nCmdShow)
{
System::Threadi ng::Thread::Cur rentThread->ApartmentSta te =
System::Threadi ng::ApartmentSt ate::STA;
Application::Ru n(new fclMain());
return 0;
}

Can anybody explain to me whats wrong?
Feb 25 '06 #1
3 7773
cnickl wrote:
VS 2005 / C++ / __gc program (converted from VS 2003)

i have this code in my program:

int found;
String *temp;
this->ofdOpen->ShowDialog() ;

the last line produces the folloing unhandleld exeption:
An unhandled exception of type 'System.Threadi ng.ThreadStateE xception'
occurred in System.Windows. Forms.dll

Additional information: Current thread must be set to single thread
apartment (STA) mode before OLE calls can be made. Ensure that your
Main function has STAThreadAttrib ute marked on it. This exception is
only raised if a debugger is attached to the process.
However my Main funtion lookes like this:

int APIENTRY _tWinMain(HINST ANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
System::Threadi ng::Thread::Cur rentThread->ApartmentSta te =
System::Threadi ng::ApartmentSt ate::STA;
Application::Ru n(new fclMain());
return 0;
}

Can anybody explain to me whats wrong?


Was the call to ofdOpen->ShowDialog from your main thread, or from another?

-cd
Feb 25 '06 #2
System::Threadi ng::Thread::Cur rentThread->ApartmentSta te =
System::Threadi ng::ApartmentSt ate::STA;

makes no sense here, it's too late to set the ApartmentState at this point,
note also that _tWinMain is also not the real entry point of this 'WinForms'
application, so it makes no sense either to set the STAThreadAttrib ute as
suggested by the error message.
All you can do is set the /CLRTHREADATTRIB UTE:STA linker switch.
Willy.

"cnickl" <cn****@discuss ions.microsoft. com> wrote in message
news:F6******** *************** ***********@mic rosoft.com...
VS 2005 / C++ / __gc program (converted from VS 2003)

i have this code in my program:

int found;
String *temp;
this->ofdOpen->ShowDialog() ;

the last line produces the folloing unhandleld exeption:
An unhandled exception of type 'System.Threadi ng.ThreadStateE xception'
occurred in System.Windows. Forms.dll

Additional information: Current thread must be set to single thread
apartment (STA) mode before OLE calls can be made. Ensure that your Main
function has STAThreadAttrib ute marked on it. This exception is only
raised
if a debugger is attached to the process.
However my Main funtion lookes like this:

int APIENTRY _tWinMain(HINST ANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR
lpCmdLine, int nCmdShow)
{
System::Threadi ng::Thread::Cur rentThread->ApartmentSta te =
System::Threadi ng::ApartmentSt ate::STA;
Application::Ru n(new fclMain());
return 0;
}

Can anybody explain to me whats wrong?


Feb 25 '06 #3
I just realized that the entire structure of code is different when you
convert a VS 2003 solution to VS 2005 compared to starting a new project in
VS 2005. VERY frustrating. I decided to start the project over in VS 2005.
Thanks anyway.

"cnickl" wrote:
VS 2005 / C++ / __gc program (converted from VS 2003)

i have this code in my program:

int found;
String *temp;
this->ofdOpen->ShowDialog() ;

the last line produces the folloing unhandleld exeption:
An unhandled exception of type 'System.Threadi ng.ThreadStateE xception'
occurred in System.Windows. Forms.dll

Additional information: Current thread must be set to single thread
apartment (STA) mode before OLE calls can be made. Ensure that your Main
function has STAThreadAttrib ute marked on it. This exception is only raised
if a debugger is attached to the process.
However my Main funtion lookes like this:

int APIENTRY _tWinMain(HINST ANCE hInstance, HINSTANCE hPrevInstance, LPTSTR
lpCmdLine, int nCmdShow)
{
System::Threadi ng::Thread::Cur rentThread->ApartmentSta te =
System::Threadi ng::ApartmentSt ate::STA;
Application::Ru n(new fclMain());
return 0;
}

Can anybody explain to me whats wrong?

Feb 26 '06 #4

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

Similar topics

2
2983
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def get_all_files(path): """return all files of folder path, scan with subfolders
1
1483
by: Ognjen Bezanov | last post by:
Hi, all Thanks all of you who helped me with the threading and queues issue. I am trying to get it working but I am having problems. When I try to run the following: cmddata = mediaplay.initcommandqueue() #initiates the Queue to send commands down
0
1271
by: Maxwell Hammer | last post by:
Hope someone can help with a problem I'm having. A python program I wrote terminates with the following traceback. *** start traceback *** Error in atexit._run_exitfuncs: Traceback (most recent call last): File "/usr/lib/python2.4/atexit.py", line 22, in _run_exitfuncs func(*targs, **kargs) File "/usr/lib/python2.4/threading.py", line 636, in __exitfunc self._Thread__delete()
2
8465
by: hnkien | last post by:
Hi, I am writing a windows service with threading.timer for 10 seconds but it didn't work. Here are my code: namespace SchedulerService { public class ScheduleService : System.ServiceProcess.ServiceBase { private System.ComponentModel.IContainer components; protected System.Threading.Timer tmrThreadingTimer;
22
4068
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
10
1613
by: MikeScullion | last post by:
I have set up this thread so my program doesn't hang while I call a cpu intensive bit of code: System.Threading.ThreadStart ThreadEncoderStart = new System.Threading.ThreadStart(myEncoder.EncodeFromConsole); System.Threading.Thread Thread_myEncoder = new System.Threading.Thread(ThreadEncoderStart); Thread_myEncoder.Name = "myEncoder"; Thread_myEncoder.Priority = System.Threading.ThreadPriority.BelowNormal;
5
3105
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when i used time.sleep in while, the function in while never executed. then i found something about Timer but couldnt realize any algorithm in my mind.
15
2579
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
3
12779
by: dedalusenator | last post by:
Hello Folks, My first posting here and I am a stuck in figuring out the exact way to update a global variable from within a function that doesnt return any value (because the function is a target of the thread and I dont know how exactly return would work in such a case). I am sure I am missing something very fundamental here. The essential pieces of my code that cause the problem would be something like this:...
1
1237
by: JoeSox | last post by:
I have two threads going class guiThread(threading.Thread) class mainThread(threading.Thread) Within the guiThread, I have an instance of class GUIFramework(Frame) in this Tkinter instance I have a ListBox. The second thread, mainThread, has an instance of a custom class the will need to send out text or other objects to the gui.
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.