Call function in c++ dll without header

前端 未结 6 571
借酒劲吻你
借酒劲吻你 2020-12-15 22:36

I would like to call a method from an dll, but i don\'t have the source neither the header file. I tried to use the dumpbin /exports to see the name of the method, but i can

6条回答
  •  执念已碎
    2020-12-15 23:28

    The C++ language does not know anything about dlls.

    Is this on Windows? One way would be to:

    • open the dll up in depends.exe shipped with (Visual Studio)
    • verify the signature of the function you want to call
    • use LoadLibrary() to get load this dll (be careful about the path)
    • use GetProcAddress() to get a pointer to the function you want to call
    • use this pointer-to-function to make a call with valid arguments
    • use FreeLibrary() to release the handle

    BTW: This method is also commonly referred to as runtime dynamic linking as opposed to compile-time dynamic linking where you compile your sources with the associated lib file.

    There exists some similar mechanism for *nixes with dlopen, but my memory starts to fail after that. Something called objdump or nm should get you started with inspecting the function(s).

提交回复
热议问题