471,086 Members | 825 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 software developers and data experts.

Error Mixing Managed and Unmanaged Code

I've never mixed managed and unmanaged C++ before, but I've done a lot
of "research" out on the web. Using some examples out there, I wrote this:

#using <mscorlib.dll>
using namespace System;

namespace ntMgdCls
{
__nogc class ntUnmgdCls
{
public:
ntUnmgdCls::ntUnmgdCls(void) {}
ntUnmgdCls::~ntUnmgdCls(void) {}
int ntUnmgdCls::DoSomethingUnmanaged(void) { return 1; }
};

public __gc class ntManagedClass
{
public:
int DoSomething(void)
{
ntUnmgdCls * umc = new ntUnmgdCls();
return umc->DoSomethingUnmanaged();
}
};
}

Essentially I want ntUnmgdCls to wrap around some C++ classes that I
need to import from a 3rd party .lib, and use that wrapper from our main
C# app. However, when I do the above, I get these linker failures:

ntMgdCls.obj : error LNK2001: unresolved external symbol "void * __cdecl
operator new(unsigned int)" (??2@$$FYAPAXI@Z)
ntMgdCls.obj : error LNK2001: unresolved external symbol "void __cdecl
operator delete(void *)" (??3@$$FYAXPAX@Z)

I'm sure it's something basic that I'm missing, and figured someone out
here could pick out what's going on in a NY second...my WY seconds are a
bit slower...

Thanks in advance!

Jared

Oct 23 '06 #1
2 1239
compile you program with /clr:oldsyntax and see if that helps

"Jared Kail" wrote:
I've never mixed managed and unmanaged C++ before, but I've done a lot
of "research" out on the web. Using some examples out there, I wrote this:

#using <mscorlib.dll>
using namespace System;

namespace ntMgdCls
{
__nogc class ntUnmgdCls
{
public:
ntUnmgdCls::ntUnmgdCls(void) {}
ntUnmgdCls::~ntUnmgdCls(void) {}
int ntUnmgdCls::DoSomethingUnmanaged(void) { return 1; }
};

public __gc class ntManagedClass
{
public:
int DoSomething(void)
{
ntUnmgdCls * umc = new ntUnmgdCls();
return umc->DoSomethingUnmanaged();
}
};
}

Essentially I want ntUnmgdCls to wrap around some C++ classes that I
need to import from a 3rd party .lib, and use that wrapper from our main
C# app. However, when I do the above, I get these linker failures:

ntMgdCls.obj : error LNK2001: unresolved external symbol "void * __cdecl
operator new(unsigned int)" (??2@$$FYAPAXI@Z)
ntMgdCls.obj : error LNK2001: unresolved external symbol "void __cdecl
operator delete(void *)" (??3@$$FYAXPAX@Z)

I'm sure it's something basic that I'm missing, and figured someone out
here could pick out what's going on in a NY second...my WY seconds are a
bit slower...

Thanks in advance!

Jared
Oct 23 '06 #2
Hi. Thanks for the suggestion!!! Unfortunately, I'm using VS2003 (.NET
1.1), so the oldsyntax trick won't work.

Anyone have any other ideas? It seems like this should be pretty
straightforward. What I am missing?

Jared

Vikas Kumar wrote:
compile you program with /clr:oldsyntax and see if that helps

"Jared Kail" wrote:

>I've never mixed managed and unmanaged C++ before, but I've done a lot
of "research" out on the web. Using some examples out there, I wrote this:

#using <mscorlib.dll>
using namespace System;

namespace ntMgdCls
{
__nogc class ntUnmgdCls
{
public:
ntUnmgdCls::ntUnmgdCls(void) {}
ntUnmgdCls::~ntUnmgdCls(void) {}
int ntUnmgdCls::DoSomethingUnmanaged(void) { return 1; }
};

public __gc class ntManagedClass
{
public:
int DoSomething(void)
{
ntUnmgdCls * umc = new ntUnmgdCls();
return umc->DoSomethingUnmanaged();
}
};
}

Essentially I want ntUnmgdCls to wrap around some C++ classes that I
need to import from a 3rd party .lib, and use that wrapper from our main
C# app. However, when I do the above, I get these linker failures:

ntMgdCls.obj : error LNK2001: unresolved external symbol "void * __cdecl
operator new(unsigned int)" (??2@$$FYAPAXI@Z)
ntMgdCls.obj : error LNK2001: unresolved external symbol "void __cdecl
operator delete(void *)" (??3@$$FYAXPAX@Z)

I'm sure it's something basic that I'm missing, and figured someone out
here could pick out what's going on in a NY second...my WY seconds are a
bit slower...

Thanks in advance!

Jared

Oct 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Daniel Lidström | last post: by
1 post views Thread by tsmith | last post: by
3 posts views Thread by Wayne Allen | last post: by
2 posts views Thread by quat | last post: by
3 posts views Thread by frank | last post: by
3 posts views Thread by frank | last post: by
2 posts views Thread by Jon Slaughter | last post: by

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.