I have a project, where I must connect to a library that is C based, and I was not able to get at the functions from C# using the DLLImport. I have to use a project that is C++/CLI based to surface these functions for use. (more to that story but not important).
I studied C++ over 10 years ago, so forgive me if this seems like it is naive.
I purchased a few books on the C++/CLI implementation last year, and have some grasp of what is involved - I only dug into those books for this project. (I have been a programmer for a long time).
I thought I had better start a small project example project to familiarize myself with what will be involved, to make sure I could compile, etc. I started a project using Visual Studio 2008 SP1; Visual C++ > CLR > Class Library. In the project - I want to use both managed and native from the DLL. So the /clr switch is used.
I have used other names in the real code; but this is very, very close. (there are no other files, or functions at this point)
Header:
//myWrapper.h
#pragma once
using namespace System;
namespace myWrapper {
public ref class myWrappedService {
myWrappedService();
bool Connected(String ^user,String ^password,String ^domain);
}
};
And the implementation has this.
//myWrapper.cpp
//This is the main DLL file
#include "stdafx.h"
#include "myWrapper.h"
using namespace System;
public ref class myWrappedService
{
public:
myWrappedService() {}
bool Connected(String ^user,String ^password,String ^domain)
{
//just a simple result to start - no real functionality
bool result = false;
return result;
}
};
That is the code - that compiles but gets linker errors.
error LNK2020: unresolved token (06000002) myWrapper.myWrappedService::Connected
fatal error LNK1120: 1 unresolved external.
This looked dead easy - and I might be thinking to much from a C# approach. I expect this to be something simple - but I am not familiar with what I should be seeing in the CLI approach. (I spent a few hours looking for answers and finally feel I need to post a question where it might get answered).