\ CLR混合模式编译困境! [英] \CLR Mixed mode compilation woes!

查看:62
本文介绍了\ CLR混合模式编译困境!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Iv将我当前的C ++项目编译为\ clr,因为我想开始将

放入某些特定的C ++ \ CLI代码中,以将我的MFC对象序列化为.NET

等价物。

程序在启动时崩溃,与堆栈框架有关

被破坏。


我的第一个问题该程序在可执行映像的大小方面已经膨胀。

当它试图运行时失败并且有关于堆栈帧的报告

腐败。


我注意到任何C文件都必须转换为C ++。


该程序链接到DLL和Libs编译为C.


将程序编译为/ CLR然后与

C libs等链接并在启动时加载C Dll时这是一个问题吗?


我如何具体指示编译器只编译特定的

函数/方法作为托管(混合模式)并保留其他所有内容

是原生的吗?

这可能吗?


提前致谢。

Iv compiled my current C++ project as \clr as i want to start putting
in some specific C++\CLI code to serialize my MFC objects to .NET
equivalents.
The program crashes on startup, something to do with the stack frame
being corrupted.

My first concern is the program has ballooned in terms of the size of
the executable image.
When it attempts to run it fails and some report about stack frame
corruption.

Iv noticed any C files have to be converted to C++.

The program links to a DLL and Libs that have been compiled as C.

Is this a problem when compiling a program as /CLR that then links with
C libs etc and on startup loads C Dlls?

How can i specifically instruct the compiler to only compiler specific
functions/methods as managed(mixed mode) and to leave everything else
as native?
Is this possible?

Thanks in advance.

推荐答案

您是否首先尝试在VC ++ 2005中成功编译并运行它

(没有打开/ clr)?这样可以吗?


-

问候,

Nish [VC ++ MVP]

Herby < PR ******** @ gmail.com>在消息中写道

news:11 ********************** @ g47g2000cwa.googlegr oups.com ...
Have you first tried just compiling and running it successfully in VC++ 2005
(without /clr turned on) ? Does it work okay then?

--
Regards,
Nish [VC++ MVP]
"Herby" <pr********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Iv将我当前的C ++项目编译为\ clr,因为我想开始将
放在某些特定的C ++ \ CLI代码中,以将我的MFC对象序列化为.NET
等价物。
该程序在启动时崩溃,与堆栈框架损坏有关。

我首先关注的是程序在可执行映像的大小方面已经膨胀。
当它试图运行它失败时,一些报告有关堆栈框架的损坏。

我注意到任何C文件都必须转换为C ++。
程序链接到已编译为C的DLL和Lib。

将程序编译为/ CLR然后链接到C libs等并在启动时加载是否存在问题C Dlls?

我如何具体指示编译器只编译特定的
函数/方法作为托管(混合模式)和留下其他一切
本土?
这可能吗?

提前致谢。
Iv compiled my current C++ project as \clr as i want to start putting
in some specific C++\CLI code to serialize my MFC objects to .NET
equivalents.
The program crashes on startup, something to do with the stack frame
being corrupted.

My first concern is the program has ballooned in terms of the size of
the executable image.
When it attempts to run it fails and some report about stack frame
corruption.

Iv noticed any C files have to be converted to C++.

The program links to a DLL and Libs that have been compiled as C.

Is this a problem when compiling a program as /CLR that then links with
C libs etc and on startup loads C Dlls?

How can i specifically instruct the compiler to only compiler specific
functions/methods as managed(mixed mode) and to leave everything else
as native?
Is this possible?

Thanks in advance.



是的,首先是未管理的,并且没有问题。

Yes compiled un-managed first and is OK.


" Herby" < PR ******** @ gmail.com>在消息中写道

news:11 ********************** @ g47g2000cwa.googlegr oups.com ...
"Herby" <pr********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Iv将我当前的C ++项目编译为\ clr,因为我想开始将
放在某些特定的C ++ \ CLI代码中,以将我的MFC对象序列化为.NET
等价物。
该程序在启动时崩溃,与堆栈框架损坏有关。

我首先关注的是程序在可执行映像的大小方面已经膨胀。
当它试图运行它失败时,一些报告有关堆栈框架的损坏。


您应该具体:它究竟是如何失败的,究竟是什么报道?

Iv注意到任何C文件都必须转换为C ++。


是的。你无法将C编译为托管代码。

程序链接到已编译为C的DLL和Libs。


那没关系。

将程序编译为/ CLR然后链接到/或C库等并且在启动时加载C Dll会出现这个问题吗?


不,这没问题。考虑操作系统本身

是C并通过DLL公开...

我如何具体指示编译器只编译特定的
函数/方法作为托管(混合模式)并将其他所有内容保留为本机?
Iv compiled my current C++ project as \clr as i want to start putting
in some specific C++\CLI code to serialize my MFC objects to .NET
equivalents.
The program crashes on startup, something to do with the stack frame
being corrupted.

My first concern is the program has ballooned in terms of the size of
the executable image.
When it attempts to run it fails and some report about stack frame
corruption.
You should be specific: exactly how is it failing, exactly what is reported?

Iv noticed any C files have to be converted to C++.
Yes. You cannot compile C as managed code.

The program links to a DLL and Libs that have been compiled as C.
That''s fine.

Is this a problem when compiling a program as /CLR that then links with
C libs etc and on startup loads C Dlls?
No, there''s no problem with that. Consider that the operating system itself
is C and is exposed through DLLs...

How can i specifically instruct the compiler to only compiler specific
functions/methods as managed(mixed mode) and to leave everything else
as native?




请参阅#pragma managed和#pragma unmanaged。您还可以仅对包含托管代码的文件抛出/ clr

编译器选项,并继续

将其他所有内容编译为本机代码。这可能会让你无需支付
插入#pragma unmanaged一堆地方。


请注意定义将在
本机和托管代码通常应写为:


// MySharedHeader.h

#pragma一次

#pragma托管(推,关)


//你的声明在这里


#pragma managed(pop)


这将确保始终看到共享头中的声明

为非托管,无论编译单元如何引用

头文件编译。


另请注意,预处理器宏(#define)既不管理也不管理
非管理 - 它们只是文本替换,所以他们会在任何一种环境中工作都相同




-cd



See #pragma managed and #pragma unmanaged. You also can throw the /clr
compiler option only on files that contain managed code and continue to
compile everything else as native code. That might save you from having to
insert #pragma unmanaged a bunch of places.

Note that header files that define declarations that will be shared between
native and managed code should generally be written as:

// MySharedHeader.h
#pragma once
#pragma managed(push, off)

// your declarations here

#pragma managed(pop)

This will ensure that the declarations in the shared header are always seen
as unmanaged regardless of how the compilation unit the references the
header file is compiled.

Note also that preprocessor macros (#define) are neither managed nor
unmanaged - they''re simply text substitutions, so they''ll work identically
in either environment.

-cd


这篇关于\ CLR混合模式编译困境!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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