Link 到 Pelles C 中的 DLL

Link to a DLL in Pelles C

我有一个 218KB .dll 和一个 596KB .so 的文件,两者的名称相同。我想 link 到 .dll 以避免 link er returns 的 "unresolved external symbol" 错误,但我找不到 [=33] 的方法=] 到 DLL 文件。

根据 this Pelles C forum topic, I need to use the .def file to create a .lib... but I don't have a .def file. This forum topic 显示如何使用 polink 从命令行创建 .lib,所以我 运行 polink /? 得到更多选项。我注意到一个 /MAKEDEF 选项,但是 运行 这与 .dll.so 一起给出了 "No library file specified" 致命错误。

我已经尝试这样做了三个小时,但我没有想法。我已经到了我的网络搜索出现我自己的帮助请求的地步。一定有办法做到这一点...我怎样才能 link 到 .dll?

根据在 header #include 中找到的信息和您的详细信息,这是一种通过从您的软件动态调用它们来替换缺失函数的方法。 1- 以下原型在#include 中:

typedef float (* XPLMFlightLoop_f)(float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop, int inCounter, void * inRefcon);

2- 您可以根据需要填写的一些常量:

const char *sDllPathName = "<Your XPLM_API DLL>.dll";
const char *sXPLMRegisterFlightLoopCallbackName = "XPLMRegisterFlightLoopCallback";

In order to confirm the sXPLMRegisterFlightLoopCallbackName, you can use the freeware Dependency Walker and check name and format of the exported functions.

3-声明外部函数的原型:

Be aware to the calling convention __cdecl or __stdcall

In the current case, the keyword XPLM_API is defined in the XPLMDefs.h as follow:

#define XPLM_API __declspec(dllexport) // meaning __cdecl calling convention

typedef void (__cdecl *XPLMRegisterFlightLoopCallback_PROC)(XPLMFlightLoop_f, float, void *);

4- 克隆函数以在您的软件中调用它:

#include <windows.h>

void XPLMRegisterFlightLoopCallback(XPLMFlightLoop_f inFlightLoop, float inInterval, void * inRefcon)
{
    HINSTANCE hInstDLL;
    XPLMRegisterFlightLoopCallback_PROC pMyDynamicProc = NULL;

    // Load your DLL in memory
    hInstDLL = LoadLibrary(sDllPathName);
    if (hInstDLL!=NULL)
    {
        // Search for the XPLM Function
        pMyDynamicProc = (XPLMRegisterFlightLoopCallback_PROC) GetProcAddress(hInstDLL, sXPLMRegisterFlightLoopCallbackName);
        if (pMyDynamicProc != NULL)
        {
            // Call the XPLM Function with the orignal parameter
            (pMyDynamicProc)(inFlightLoop,inInterval,inRefcon);
            return;
        }
    }
    // Do something when DLL is missing or function not found
}

5- 只需添加您描述的调用:

...
XPLMRegisterFlightLoopCallback(callbackfunction, 0, NULL);
...