R
Roland
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::Finalize
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:irectShowHandler(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
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::Finalize
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:irectShowHandler(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