469,582 Members | 2,300 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,582 developers. It's quick & easy.

Managed and unmanaged C++: error LNK2020: unresolved token

Hi,

ultimately I want to call some unmanaged C++ class that contains some
DirectShow code of mine from my C# classes, but for the time being I'd
be happy if I could get this to build! I have read the other topics on
the same problem here on the groups but haven't found the solution to
my problem yet.

I have written a managed C++ wrapper class called MDirectShowHandler.
This currently wraps only the constructor and destructor calls (see
code below) in the unmanaged class DirectShowHandler. When I try to
build this, the .obj files are created but the linker throws errors:

error LNK2020: unresolved token (06000001)
ManagedDirectShowHandler.MDirectShowHandler::.ctor
error LNK2020: unresolved token (06000002)
ManagedDirectShowHandler.MDirectShowHandler::Final ize
error LNK2020: unresolved token (06000002) delete
fatal error LNK1120: 3 unresolved externals

Here are the 4 files:

ManagedDirectShowHandler.h:
---------------------------
#pragma once
#include "DirectShowHandler.h"
#pragma managed
#using <mscorlib.dll>
using namespace System;

namespace ManagedDirectShowHandler
{
public __gc class MDirectShowHandler
{
public:
MDirectShowHandler();
~MDirectShowHandler();
private:
DirectShowHandler __nogc* m_pDirectShowHandler;
};
}

ManagedDirectShowHandler.cpp:
-----------------------------
#pragma once
#include "stdafx.h"

#include "ManagedDirectShowHandler.h"

public __gc class MDirectShowHandler
{
public:
MDirectShowHandler::MDirectShowHandler()
{
m_pDirectShowHandler = new DirectShowHandler();
}

MDirectShowHandler::~MDirectShowHandler()
{
m_pDirectShowHandler->~DirectShowHandler();
}
private:
DirectShowHandler __nogc* m_pDirectShowHandler;
};

DirectShowHandler.h:
--------------------
#pragma once
#pragma unmanaged

class DirectShowHandler
{
public:
DirectShowHandler(void);
~DirectShowHandler(void);
};

DirectShowHandler.cpp:
----------------------
#include "StdAfx.h"
#include ".\directshowhandler.h"
#include <iostream>
#using <mscorlib.dll>
using namespace std;

// Constructor for DirectShowHandler (this class is unmanaged)
DirectShowHandler::DirectShowHandler(void)
{
cout << "DirectShowHandler created" << endl;
}

DirectShowHandler::~DirectShowHandler(void)
{
cout << "DirectShowHandler destroyed" << endl;
}
The Visual Studio project is set to .NET Class Library, so that it
should create a DLL which I can then add to my C# project.

Any ideas why the errors mentioned above occur? This is quite
frustrating as there don't seem to be any good examples that take you
through it step by step.

Thanks,

Roland

Nov 17 '05 #1
0 2493

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Tony Baker | last post: by
3 posts views Thread by Ulrich Sprick | last post: by
3 posts views Thread by amirbehzadan | last post: by
3 posts views Thread by =?Utf-8?B?TkVXMi5ORVQ=?= | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.