-
January 4th, 2011, 04:09 PM
#1
late binding, InvokeMember managed C++
Hi I am trying to load a c# dll at runtime and call a method in it from managed C++, I am not having much luck
I am trying t use
Assembly::LoadFrom and
System::Type^ typ
typ->InvokeMember
methods.
anyone have sample code in managed C++.
Urgent. Please and thank you.
Indika
and Canada rocks!! Peace bro.
-
January 5th, 2011, 05:24 AM
#2
Re: late binding, InvokeMember managed C++
-
January 6th, 2011, 02:06 PM
#3
Re: late binding, InvokeMember managed C++
This works for me (using VC++ 2010 Express):
Code:
// 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 02: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.
-
January 6th, 2011, 02:19 PM
#4
Re: late binding, InvokeMember managed C++
Thanks... yes that will do the trick. I had already fixed with similar code as yours.
and Canada rocks!! Peace bro.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|