I have a C++ Windows Forms Application. I want this application to be able to use various custom modules contained in "C++ Class Library" (dll) files, that will all have the same public function calls in them but will do different things. The dll may also have other support functions that the dll uses, but are private. These private functions will change from one dll to another. The program will not know what dlls are available, it'll scan a folder and load in whatever it finds on startup.
I have the class library concept working when adding the DLL as a reference in the main app... and instantiating/using it like this simplified example:
C++ Class Library: compiles to dll:
using namespace System;
public ref class Module_Test {
public:
Module_Test(void) { a = 500; }
private:
int a;
public: int GetNumber() { return a; }
};
C++ Windows Forms Application excerpt:
Module_Test md1;
MessageBox::Show(String::Format("{0}", md1.GetNumber()), "This will display the number 500", MessageBoxButtons::OK, MessageBoxIcon::Information);
So, to make it work as intended, I believe that I need to use LoadLibrary() and GetProcAddress(), and while LoadLibrary(L"Module_Test.dll") works... I'm not quite sure where to go from there. I can't seem to get GetProcAddress() to find the GetNumber() test function, nor do I know how to cast it or instantiate it to be able to use the whole class as I do above via the use of a reference.
I've googled just about every combination of words I can think of, no luck. I've found lots of simialr examples, but they're often not applicable because they're different kinds of code... unmanaged, older c++ code dll, etc. I can't find any newer examples that work with with the Visual Studio 2010 project types I'm using here.
Thoughts?