Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DLL load and call class method

Tags:

dll

visual-c++

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++

like image 985
Gaurav Avatar asked Oct 14 '25 03:10

Gaurav


1 Answers

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.

like image 133
Roger Rowland Avatar answered Oct 18 '25 04:10

Roger Rowland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!