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::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
Profound_Darkness - 14 Jul 2005 20:45 GMT
Hello, I just sorta stumbled on a possible solution to your (and my
quandry. I myself have been trying to figure out how to create a C+
.net class for use in a vb.net project. My C knowledge is extreeml
poor but up to the task of the C code I need to make, just not how t
get that code to work with an external program. btw: I do have som
java experience which makes some C structures to code easier t
understand.
I was also having a problem getting a simple test to compile.
defined a function int Hello() in the .h file and then in the cpp fil
I had only one line of code: return 10;
This was just to test and see how to get communications up but I kep
getting the same linking error as yourself. I tried a variety o
things and then remembered something about objects in C++ using doubl
: (ex ::) to reference sub parts of objects. Following the belo
mentioned setup I get something that compiles and works with my vb.ne
code. (Note that there was some trial and error before this point).
ProjectName::ClassName::MethodName(){
Code;
}
ProjectName is the name of the project you setup. Classname is what i
defined in the .h file where the helper sais to put your methodnames at
MethodName is... well, your method name.
I hope this helps