紧急:混合托管/非托管C ++ [英] URGENT: Mixing Managed/unmanaged C++

查看:84
本文介绍了紧急:混合托管/非托管C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我写了一个托管C ++类的Dll,其中包含一段代码,如

跟随liines。

这个代码在尝试创建一个新的非托管类时总是失败。

有人有解释吗?


请帮助

Pascal


// Il s''agit du fichier DLL principal。


#include" stdafx.h"

#include" TestEmbended.h"

#using< mscorlib.dll>

使用命名空间系统;


namespace TestEmbended

{


public __gc class Class1

{

public:

__nogc class CEmbeded

{

public:

void toto(){};

};


CEmbeded * ce;


Class1(无效)

{

ce = new CEmbeded(); //在这里执行

ce-> toto();

};


};

}

解决方案

Pascal Cloup写道:


你好,

我编写了一个托管C ++类的DLL,其中包含一段代码,如
以下内容。
此代码在尝试创建新的非托管类时总是失败。有人有解释吗?

请帮助
Pascal

// Il s''agit du fichier DLL主管。
#include" stdafx.h"
#include" TestEmbended.h"
#using< mscorlib.dll>
使用命名空间系统;

名称空间TestEmbended
公共__gc班Class1
公共:
__nogc class CEmbeded
{
公开: void toto(){};
};

CEmbeded * ce;

Class1(无效)
{
ce = new CEmbed ED(); //在这里执行
ce-> toto();
};

};
}




尝试更改:


CEmbeded * ce;


to:


CEmbeded __nogc * ce;


" Pascal Cloup" < PA ********** @ biogesta.fr>在消息新闻中写道:< ex ************** @ TK2MSFTNGP11.phx.gbl> ...

你好,

我编写了一个托管C ++类的DLL,其中包含一段代码,如
以下内容。
这个代码在尝试创建一个新的非托管类时总是失败。
有人有解释吗?

请帮助
Pascal

//这是一个很好的DLL主管。

#include" stdafx.h" ;
#include" TestEmbended.h"
#using< mscorlib.dll>
使用命名空间系统;

命名空间TestEmbended
{

public __gc class Class1
{
public _
__nogc class CEmbeded
{
public:
void toto(){};
};

CEmbeded * ce;

Class1(无效)
{
ce = new CEmbeded(); //在这里执行
ce-> toto();
};

};
}




我没有看到你的声明有什么问题。什么例外

你得到了什么版本的VC ++?





感谢您的回答。


尝试Julie的建议什么都不做。

错误是:


Une例外非'géréedu''System.NullReferenceException's''est

produite dans testembended.dll

信息supplémentaires:Laréférenced''objetn'' estpasdéfinieàune

instance d''un objet。


我使用

Visual Studio 2003 vers 7.1.3088

..NET Framework 1.1 vers 1.1.4322

我记得我在使用

生成dll时遇到了问题链接器:代码行''ce = new CEmbeded(); ''生成链接错误:

错误LNK2001:symbole externenonrésolu" void * __cdecl operator

new(unsigned int)" (α 2 @

Hello,

I write a Dll of managed C++ class that contains a piece of code like the
following liines.
This code always fails when attempting to create a new not managed class.
Someone has an explanation?

Help please
Pascal

// Il s''agit du fichier DLL principal.

#include "stdafx.h"
#include "TestEmbended.h"
#using <mscorlib.dll>
using namespace System;

namespace TestEmbended
{

public __gc class Class1
{
public:
__nogc class CEmbeded
{
public:
void toto() {};
};

CEmbeded *ce;

Class1(void)
{
ce = new CEmbeded(); // Exeption here
ce->toto();
};

};
}


解决方案

Pascal Cloup wrote:


Hello,

I write a Dll of managed C++ class that contains a piece of code like the
following liines.
This code always fails when attempting to create a new not managed class.
Someone has an explanation?

Help please
Pascal

// Il s''agit du fichier DLL principal.

#include "stdafx.h"
#include "TestEmbended.h"
#using <mscorlib.dll>
using namespace System;

namespace TestEmbended
{

public __gc class Class1
{
public:
__nogc class CEmbeded
{
public:
void toto() {};
};

CEmbeded *ce;

Class1(void)
{
ce = new CEmbeded(); // Exeption here
ce->toto();
};

};
}



Try changing:

CEmbeded *ce;

to:

CEmbeded __nogc *ce;


"Pascal Cloup" <pa**********@biogesta.fr> wrote in message news:<ex**************@TK2MSFTNGP11.phx.gbl>...

Hello,

I write a Dll of managed C++ class that contains a piece of code like the
following liines.
This code always fails when attempting to create a new not managed class.
Someone has an explanation?

Help please
Pascal

// Il s''agit du fichier DLL principal.

#include "stdafx.h"
#include "TestEmbended.h"
#using <mscorlib.dll>
using namespace System;

namespace TestEmbended
{

public __gc class Class1
{
public:
__nogc class CEmbeded
{
public:
void toto() {};
};

CEmbeded *ce;

Class1(void)
{
ce = new CEmbeded(); // Exeption here
ce->toto();
};

};
}



I dont see anything wrong with your declaration. what exception are
you getting and what version of the VC++ are you using?


Hi,

thanks for answers.

Trying what Julie has suggested changes nothing.
The Error is:

Une exception non gérée du type ''System.NullReferenceException'' s''est
produite dans testembended.dll
Informations supplémentaires : La référence d''objet n''est pas définie à une
instance d''un objet.

I use
Visual Studio 2003 vers 7.1.3088
..NET Framework 1.1 vers 1.1.4322

I remember that i had encountered a problem for generating the dll with the
linker: The code line ''ce = new CEmbeded(); '' generated a link error :
error LNK2001: symbole externe non résolu "void * __cdecl operator
new(unsigned int)" (??2@


这篇关于紧急:混合托管/非托管C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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