What I understand of your problem is you need to show a form within a managed C# DLL called from a native C++ DLL. This can be done, I have used this in some of my projects. I have created a quick C++ console application (same code can be place in a DLL), project source code CallManagedFromNative.
The other solution is to create a native C++ project that can capture webcam data, say using Microsoft Media Foundation, if this is of interest the source code can be found at MediaFoundation.
Anyway back to the native C++ calling managed C# form sample.
#include "stdafx.h"
#include <iostream>
#include "BaseNativeProxy.h"
#include "BaseTypes.h"
using namespace Nequeo::System::Any;
int main()
{
std::vector<boost::any> param;
param.push_back(3);
boost::any returnData;
Nequeo::NativeProxy managedProxy(L"ClassLibraryManaged.dll", L"ClassLibraryManaged.Class1");
managedProxy.executeManaged(L"OpenForm", param, returnData);
int retFromCall = boost::any_cast<int>(returnData);
std::cout << retFromCall;
return 0;
}
Specify the managed DLL, the namespace and class name. Now call a method passing parameters and optionally a return value. The code in the managed DLL:
namespace ClassLibraryManaged
{
public class Class1
{
public Class1() { }
public int OpenForm(int a)
{
TestForm form = new TestForm();
form.ShowDialog();
return a * a;
}
}
}
The sample project contains all the includes, bins and libs you will need to test your project, the only thing you will need is boost
I used version 161 for this project you can use your own build or you can download my build from BoostBuild161
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…