URGENT Mixing Managed/unmanaged C++

P

Pascal Cloup

Hello,

I encounter problems during execution of code like the followng that is part
of Dll of managed C++ classes.
When attempting to create the not managed objet (instance of CA) i always
get the exception:
.....System.NullReferenceException....
La référence d'objet n'est pas définie à une instance d'un objet ( after
translation: The reference of object is not defined to an instance of an
object)

Somone (from microsoft?) can explain this, or better, give the right method
to create such
unmaged object inside method of managed class?

Thanks for help,
Pascal Cloup

__nogc class CA : public IUnknown

{

public:

CA(void){}

// IUnknown methods.

.......

};

__gc class CB

{

public:

.....

CA __nogc *aCA;

CB(void)

{

aCA = __nogc new CA(); // THE PROBLEM IS HERE

}

....

}





....
 
R

Ronald Laeremans [MSFT]

Could you post a full repro case (A something containing all the lines of
code needed to reproduce the problem plus the version of the compiler and
CLR you build it with)?

Thanks.

Ronald Laeremans
Visual C++ team
 
P

Pascal Cloup

Dear Ronald,

You will wild find below all the lines of an example that reproduces the
error.
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@$$FYAPAXI@Z)

To solve these error i just added the libc;lib in the dll project.I suppose
that my is at this level.

Thanks for helping

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();

};

};

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top