链接到Pelles C中的DLL [英] Link to a DLL in Pelles C

查看:137
本文介绍了链接到Pelles C中的DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个218KB .dll 和一个596KB .so 文件,它们都具有相同的名称。我想链接到 .dll 以避免链接器返回的无法解析的外部符号错误,但是我找不到链接到DLL文件的方法。

I have a 218KB .dll and a 596KB .so file, both with identical names. I want to link to the .dll to avoid the "unresolved external symbol" error that the linker returns, but I can't find a way to link to the DLL file.

根据此Pelles C论坛主题,我需要使用 .def 文件创建一个 .lib ...,但是我没有没有 .def 文件。 此论坛主题显示了如何使用 polink 从命令行创建 .lib ,因此我运行了 polink /?以获得更多选项。我注意到一个 / MAKEDEF 选项,但是同时使用 .dll 运行它。所以给出了未指定库文件的致命错误。

According to 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 shows how to use polink to create a .lib from the command line, so I ran polink /? to get some more options. I noticed a /MAKEDEF option, but running this with both the .dll and the .so gives a "No library file specified" fatal error.

我已经尝试了三个小时,但是没有主意。我已经到了我的网络搜索出现我自己的帮助请求的地步。必须有一种方法可以......如何链接到 .dll

I have been trying to do this for three hours, and am out of ideas. I have got to the point where my web searches turn up my own help-requests. There must be a way to do this... How can I link to a .dll?

推荐答案

使用在标题#include和您的详细信息中找到的信息,这是一种通过从软件动态调用缺少的函数的方法。
1-以下原型在#include中:

With information found in the header #include and your details, here is a way to replace the missing function by calling them dynamically from your software. 1- the following prototype is in #include :

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

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

2- some const that you can fill as needed:

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




为了确认 sXPLMRegisterFlightLoopCallbackName ,则您可以
使用免费软件 Dependency Walker 并检查$的名称和格式b $ b导出的函数。

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

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

3- declare the prototype of the external function:


请注意调用约定 __ cdecl __ stdcall

在当前情况下,在 XPLMDefs.h XPLM_API $ c>如下:

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-克隆该函数以在您的软件中调用它:

4- clone the function to call it in your software:

#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-只需添加您描述的通话:

5- just add your described call:

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

这篇关于链接到Pelles C中的DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆