// TestDLL.h
#pragma once
using namespace System;
namespace TestDLL {
public ref class Class1
{
public:
static void SayHello();
};
}
Code:
// TestDLL.cpp
#include "stdafx.h"
#include "TestDLL.h"
using namespace TestDLL;
void Class1::SayHello()
{
Console::WriteLine("Hello from the DLL!");
}
Code:
// MCppDllTest.cpp: Hauptprojektdatei.
#include "stdafx.h"
using namespace System;
using namespace System::Reflection;
int main(array<System::String ^> ^args)
{
#ifdef _DEBUG
String ^strDllName = "..\\Debug\\TestDLL.dll";
#else
String ^strDllName = "..\\Release\\TestDLL.dll";
#endif
Console::WriteLine("Hello World from the main app");
Assembly ^ably = Assembly::LoadFrom(strDllName);
Type ^cls = ably->GetType("TestDLL.Class1");
cls->InvokeMember("SayHello", BindingFlags::Static | BindingFlags::Public | BindingFlags::InvokeMethod,
nullptr, nullptr, nullptr);
Console::WriteLine("Back in the main app");
Console::ReadLine();
return 0;
}
Does this model your scenario, more or less? Ok, the DLL is C++/CLI here because I don't have C# installed, but I suspect the invoking part to be the problematic one anyway. If your scenario differs significantly in any aspect (except the C#), please let me know. And a more detailed description of the problem than "I am not having much luck" would have been helpful, of course.
It took me some time to put that together, including lots of debugging. But now this one works. I'm relatively sure, however, that I had it this way before and it did not work. But never mind, now...
Last edited by Eri523; January 6th, 2011 at 01:14 PM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Bookmarks