DLL load and call class method

2020-07-23 09:06发布

问题:

To load a DLL and call function in VC++, we use LoadLibrary and GetProcAddress , which needs mangled name of the method. Does it instantiate a class object and then call the method?

If it does not then how can I call a method in a class but instantiating an object of the class and then call a method?

What is process to load .h file, load class, instantiate object and then call a method in VC++

回答1:

There is actually a very good example on CodeProject that describes exactly how to do this.

EDIT with reference to your comment, if you read the above article, you'll see that GetProcAddress() does nothing more than return a function pointer. If you want to create an instance of a class that's exported from the DLL, you have to allocate memory and force the system to invoke the constructor of the class to instantiate it there. Once that's done, however, I'm sort of assuming that you can call functions defined in the class in the normal way by using the object you just created.