0

I am trying to (vs2015, c++) access the classes and methods of an external dll. I dont have the .h nor the .lib file of that dll. I can see from dumpbin.exe that the dll has following unmangled/mangled methods:

    Controller::PositionAt(double,double)
    ?PositionAt@Controller@@UEAAXNN@Z
    
    void MoveTo(double,double)
    ?MoveTo@@YAXNN@Z

    class Controller * GetController(void)
    ?GetController@@YAPEAVController@@XZ

I can load the dll and use the MoveTo() function succesfully with:

typedef void(__stdcall *f_func) (double x, double y);
HINSTANCE hdl = LoadLibraryA("C:\\Plug-in.dll");
f_func func = (f_func)GetProcAddress(hdl, "?MoveTo@@YAXNN@Z");
func((double) 1,(double) 2);

But the PositionAt() function fails. It seems I have to load the Controller class first, which apparently I am able to, using:

typedef void * (__stdcall *MyController)(void);
static MyController Ptr_MyController = NULL;
Ptr_MyController = (MyController)GetProcAddress((HINSTANCE) hdl, (LPCSTR) "?GetController@@YAPEAVController@@XZ"); 
void* MyController;
MyController = Ptr_MyController();

But I am failing to understand how do use the method PositionAt() of this class.

Thanks in advance!

Don I
  • 91
  • 10
  • PositionAt is a class member function so you need a Controller::PositionAt* function pointer to bind to it. See https://stackoverflow.com/questions/12662891/how-can-i-pass-a-member-function-where-a-free-function-is-expected – Kjell-Olov Högdahl Dec 13 '20 at 12:18
  • Thank you for your answer! I have not seen this question. Yet if my Mycontroller is returning void* and I define my PositionAt() as f_func2 func2 = (f_func2)GetProcAddress(hdl, "?PositionAt@Controller@@UEAAXNN@Z") - then how would I use the forwarder(), or function1() in your link? I am getting compiler erros.. – Don I Dec 13 '20 at 13:05
  • Unfortunately I can't answer that from the top of my head. But if you search the web for "linking to class member function in dll" you will get a bunch of clues. The Issue is you have to figure out how you make your caller get a proper C++ class member function pointer from the getProcAddress returned void* :). Good luck! You will learn some interesting stuff! Please report your solution here if you succeed :). I need a fresh up! – Kjell-Olov Högdahl Dec 17 '20 at 10:58

0 Answers0