VC 2005 Beta 2:如何设置STA ApartmentState [英] VC 2005 Beta 2: How to set STA ApartmentState

查看:56
本文介绍了VC 2005 Beta 2:如何设置STA ApartmentState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。


我正在将应用程序VC 2003移至VC 2005 Beta2。我需要设置STA

ApartmentState模型所以拖拽& drop registration可以工作。


我以前做过

System :: Threading :: Thread :: CurrentThread-> ApartmentState =

System :: Threading :: ApartmentState :: STA;

作为_tWinMain的第一个语句,也是我混合模式的DllMain

程序集。


在VC 2005上,我不能在DllMain中做这个判断,所以我被Carl导演

Daniel和Kapil来创建一个类的静态实例

其构造函数的声明。我在所有

混合模式DLL中包含了类似下面的类,希望静态实例可以在

..cctors上初始化。


__gc class QIVCadCctor

{

public:

QIVCadCctor()

{

System :: Threading :: Thread :: CurrentThread-> ApartmentState =

System :: Threading :: ApartmentState :: STA;

}


静态QIVCadCctor * cadCctor =新QIVCadCctor();

};


即使这样做,当程序试图执行


System :: Threading :: Thread :: CurrentThread-> ApartmentState =

System :: Threading :: ApartmentState :: STA;
_bWinMain上的
,我在调试输出窗口中收到以下错误消息:


托管调试助手''InvalidApartmentStateChange''检测到
'c:\ Fontes \QiCad.NET \QiCad.NET.exe'中的
问题。

附加信息:主题正试图将公寓状态设为

到STA,但它已经设置为MTA。

请参阅

C:\ WINDOWS \\ \\ microsicoft.NET\Framework\v2.0.50215\sdk\ bin \ mdaBoilerplate.exe.mda.config

的文档。


有谁知道遗漏了什么?


提前致谢。


问候,

Adriano。

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
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
as the first statment of _tWinMain and also in the DllMain of my mixed mode
assemblies.

On VC 2005 I can''t do this statment in DllMain, so I was oriented by Carl
Daniel and Kapil to create a static instance of a class that makes the
statment on its constructor. I included a class like the following in all
mixed mode DLLs, hoping the static instances would be initialized on the
..cctors.

__gc class QIVCadCctor
{
public:
QIVCadCctor()
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
}

static QIVCadCctor* cadCctor = new QIVCadCctor();
};

Even doing this, when the program tries to execute

System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;

on _tWinMain, I get the following error message on my debug output window:

Managed Debugging Assistant ''InvalidApartmentStateChange'' has detected a
problem in ''c:\Fontes\QiCad.NET\QiCad.NET.exe''.
Additional Information: Thread is attempting to set the apartment state
to STA, but it has already been set to MTA.
See
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\sdk\ bin\mdaBoilerplate.exe.mda.config
for documentation.

Does anyone know what is missing?

Thanks in advance.

Regards,
Adriano.

推荐答案

Adriano Coser写道:
Adriano Coser wrote:
你好。

我正在将一个应用程序VC 2003移动到VC 2005 Beta2。我需要设置STA
ApartmentState模型所以拖拽& drop registration可以工作。

我曾经做过
System :: Threading :: Thread :: CurrentThread-> ApartmentState =
System :: Threading :: ApartmentState :: STA ;
作为_tWinMain的第一个声明以及我的
混合模式组件的DllMain。

在VC 2005上我不能在DllMain中做这个声明,所以我由Carl Daniel和Kapil导演创建一个类的静态实例,使其构造函数的
语句。我在
所有混合模式DLL中包含了类似下面的类,希望静态实例可以在.cctors上初始化。

__gc class QIVCadCctor
{<公共:
QIVCadCctor()
{System :: Threading :: Thread :: CurrentThread-> ApartmentState =
System :: Threading :: ApartmentState :: STA ;


静态QIVCadCctor * cadCctor = new QIVCadCctor();
};

即使这样做,当程序试图执行时系统:: Threading :: Thread :: CurrentThread-> ApartmentState =
System :: Threading :: ApartmentState :: STA;

_tWinMain,我得到了我的调试输出窗口上显示以下错误消息:
托管调试助手''InvalidApartmentStateChange''已在'c:\ Fontes \QiCad.NET \ QiCad中检测到问题。 NET.exe''。
附加信息:线程正试图将公寓状态设置为STA,但它已经是设置为MTA。
请参阅
C:\ WINDOWS \ MicroSoft \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ >用于文档。

有谁知道缺少什么?
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
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
as the first statment of _tWinMain and also in the DllMain of my
mixed mode assemblies.

On VC 2005 I can''t do this statment in DllMain, so I was oriented by
Carl Daniel and Kapil to create a static instance of a class that makes
the
statment on its constructor. I included a class like the following in
all mixed mode DLLs, hoping the static instances would be initialized on
the .cctors.

__gc class QIVCadCctor
{
public:
QIVCadCctor()
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
}

static QIVCadCctor* cadCctor = new QIVCadCctor();
};

Even doing this, when the program tries to execute

System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;

on _tWinMain, I get the following error message on my debug output
window:
Managed Debugging Assistant ''InvalidApartmentStateChange'' has
detected a problem in ''c:\Fontes\QiCad.NET\QiCad.NET.exe''.
Additional Information: Thread is attempting to set the apartment
state to STA, but it has already been set to MTA.
See
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\sdk\ bin\mdaBoilerplate.exe.mda.config
for documentation.

Does anyone know what is missing?




我不能告诉你任何非常具体的东西,但很清楚 - 某事否则是
运行,无论是在DllMain本身,还是已经调用了

CoInitializeEx的.cctor,并将当前线程设置为MTA的一部分。您可以通过在CoInitializeEx()处设置断点来调试它,并且

检查调用堆栈。


-cd



I can''t tell you anything very specific, but clearly - something else is
running, either in DllMain itself, or in the .cctor that has already called
CoInitializeEx and set the current thread to be part of the MTA. You might
be able to debug it by setting a breakpoint at CoInitializeEx(), and
examining the call stack.

-cd


你好卡尔。


我在代码中没有找到任何CoInitialize或CoInitializeEx的调用。另外,

我不知道如何在这个函数上设置断点。


在_tWinMain之前,是否还有其他原因让ApartmentState设置为MTA

入场点?


感谢您的帮助。


Adriano。

AltoQi - TecnologiaAplicadaàEngenhariaAdriano Coser Departamento de

Desenvolvimento电话:(48)239-7000 ramal:7069电子邮件: co *** @ altoqi.com.br

网站: www.altoqi.com.br

Carl Daniel [VC ++ MVP]" < cp ***************************** @ mvps.org.nospam>

escreveu na mensagem新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...
Hello Carl.

I didn''t find any calls to CoInitialize or CoInitializeEx in my code. Also,
I don''t know how to set a breakpoint over this function.

Is there any other cause to ApartmentState to set to MTA before _tWinMain
entry point?

Thanks for your help.

Adriano.
AltoQi - Tecnologia Aplicada à Engenharia Adriano Coser Departamento de
Desenvolvimento Tel.: (48) 239-7000 ramal: 7069 e-mail: co***@altoqi.com.br
website: www.altoqi.com.br
"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
escreveu na mensagem news:%2****************@TK2MSFTNGP10.phx.gbl...
Adriano Coser写道:
Adriano Coser wrote:
您好。

我正在将VC 2003应用程序迁移到VC 2005 Beta2。我需要设置STA
ApartmentState模型所以拖拽& drop registration可以工作。

我曾经做过
System :: Threading :: Thread :: CurrentThread-> ApartmentState =
System :: Threading :: ApartmentState :: STA ;
作为_tWinMain的第一个声明以及我的
混合模式组件的DllMain。

在VC 2005上我不能在DllMain中做这个声明,所以我由Carl Daniel和Kapil导演创建一个类的静态实例,使其构造函数的
语句。我在
所有混合模式DLL中包含了类似下面的类,希望静态实例可以在.cctors上初始化。

__gc class QIVCadCctor
{<公共:
QIVCadCctor()
{System :: Threading :: Thread :: CurrentThread-> ApartmentState =
System :: Threading :: ApartmentState :: STA ;


静态QIVCadCctor * cadCctor = new QIVCadCctor();
};

即使这样做,当程序试图执行时系统:: Threading :: Thread :: CurrentThread-> ApartmentState =
System :: Threading :: ApartmentState :: STA;

_tWinMain,我得到了我的调试输出窗口上显示以下错误消息:
托管调试助手''InvalidApartmentStateChange''已在'c:\ Fontes \QiCad.NET \ QiCad中检测到问题。 NET.exe''。
附加信息:线程正试图将公寓状态设置为STA,但它已经是设置为MTA。
请参阅
C:\ WINDOWS \ MicroSoft \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ >用于文档。

有谁知道缺少什么?
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
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
as the first statment of _tWinMain and also in the DllMain of my
mixed mode assemblies.

On VC 2005 I can''t do this statment in DllMain, so I was oriented by
Carl Daniel and Kapil to create a static instance of a class that makes
the
statment on its constructor. I included a class like the following in
all mixed mode DLLs, hoping the static instances would be initialized on
the .cctors.

__gc class QIVCadCctor
{
public:
QIVCadCctor()
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
}

static QIVCadCctor* cadCctor = new QIVCadCctor();
};

Even doing this, when the program tries to execute

System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;

on _tWinMain, I get the following error message on my debug output
window:
Managed Debugging Assistant ''InvalidApartmentStateChange'' has
detected a problem in ''c:\Fontes\QiCad.NET\QiCad.NET.exe''.
Additional Information: Thread is attempting to set the apartment
state to STA, but it has already been set to MTA.
See
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\sdk\ bin\mdaBoilerplate.exe.mda.config
for documentation.

Does anyone know what is missing?



我不能告诉你任何非常具体的内容,但很清楚 - 其他的东西是您可以通过设置断点来调试它在CoInitializeEx(),
和检查调用堆栈。




I can''t tell you anything very specific, but clearly - something else is
running, either in DllMain itself, or in the .cctor that has already
called CoInitializeEx and set the current thread to be part of the MTA.
You might be able to debug it by setting a breakpoint at CoInitializeEx(),
and examining the call stack.

-cd



你好卡尔。


我刚才意识到我创建的静态实例在我的DLL上设置了公寓

状态(如下所示)之前没有初始化_tWinMain。


我在DllMain和QIVCadCctor的构造函数上放置了断点,而

程序只在DllMain上停止。这可能是问题吗?我还能做什么

在混合模式DLL初始化时调用托管代码?


__gc class QIVCadCctor

{

public:

QIVCadCctor()

{

System :: Threading :: Thread :: CurrentThread-> ApartmentState =

系统::线程:: ApartmentState :: STA;

}

静态QIVCadCctor * cadCctor = new QIVCadCctor();

};


感谢您的帮助。

Adriano。
Hi Carl.

I''ve just realized that the static instances I created to set the apartment
state on my DLLs (like the following) are not initialized before _tWinMain.

I put breakpoints on DllMain and on the constructor of QIVCadCctor and the
program only stops on DllMain. Could this be the problem? What else can I do
to call managed code on a mixed mode DLL initialization?

__gc class QIVCadCctor
{
public:
QIVCadCctor()
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
}
static QIVCadCctor* cadCctor = new QIVCadCctor();
};

Thanks for your help.
Adriano.


这篇关于VC 2005 Beta 2:如何设置STA ApartmentState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆