从dll导入结构(非托管到Win32控制台应用程序 [英] Import Structure from dll (unmanaged to win32 console application

查看:67
本文介绍了从dll导入结构(非托管到Win32控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

---------------------结构

---------------------structure in dll

#pragma pack(1)
    struct __declspec(dllexport)  summary
    {
        char DeviceName[300];
        char DeviceId[15];
        char DeviceClass[10];
        char DeviceComport[6];   
        unsigned long long DevicelongId;
        int DeviceCount;
    }Summary[100];



-------------------------在控制台应用程序中

在.h



-------------------------in console application

in .h

struct __declspec(dllimport)  summary
{
    char DeviceName[300];
    char DeviceId[15]; 
    char DeviceClass[10];
    char DeviceComport[6];   
    unsigned long long DevicelongId;
    int DeviceCount;
}Summary[100];



在.c文件中



in .c file

    HINSTANCE  hMod = LoadLibrary (L"BTCdll.dll");
if (NULL == hMod)
    printf ("LoadLibrary failed\n");
else
    printf ("LoadLibrary LOADED\n");

FARPROC initfn = GetProcAddress(hMod,  (LPCSTR)MAKEWORD(4,0));

    initfn();// some init function which loads correctly

    //i want structure like
    printf("%d",Summary[1]->DeviceCount);



如何在控制台应用程序代码中导入我的结构?


[edit originator ="01.mandar"]
dll导出详细信息



How to import my structure in the console application code ?


[edit originator="01.mandar"]
dll export details

==================================================
Function Name     : public: struct summary & __thiscall summary::operator=(struct summary const &)
Address           : 0x1002708c
Relative Address  : 0x0002708c
Ordinal           : 2 (0x2)
Filename          : BTCdll.dll
Full Path         : D:\BTCdll.dll
Type              : Exported Function        <<<=====(this is struct summary..!)
==================================================

==================================================
Function Name     : int __cdecl BT_Initialise2(void)
Address           : 0x10027d7f
Relative Address  : 0x00027d7f
Ordinal           : 3 (0x3)
Filename          : BTCdll.dll
Full Path         : D:\BTCdll.dll
Type              : Exported Function
==================================================


我已经制作了BTCdll.dll并导出了2个struct和2个函数.我可以LoadLibrary并成功调用2函数.
当执行函数init时,它将填充我要在控制台应用程序中导入的2个结构.

我可以
吗 ----在BTCdll.h中
包括类似
的结构


i have made the BTCdll.dll and exported 2 struct and 2 function. I can LoadLibrary and call 2 function successfully.
when the function init is executed it will populate the 2 struct which i want to import in console application.

can I
----in BTCdll.h
include the struct like

struct __declspec(dllimport)  summary
    {
        char DeviceName[300];
        char DeviceId[15];
        char DeviceClass[10];
        char DeviceComport[6];   
        unsigned long long DevicelongId;
        int DeviceCount;
    }Summary[100];


我可以如何获取填充的摘要[100]"

---在console.c


can i some how get "Summary[100]" which is populated

--- in console.c

FARPROC mystruct= GetProcAddress(hMod,  (LPCSTR)MAKEWORD(2,0));

int cnt=mystruct[3]->DeviceCount;



[/edit]



[/edit]

推荐答案

您需要Summary结构的序数或名称,必须再次通过GetProcAddress()获取.如果这不是您自己的dll(我认为不是),请使用文档或 Dependency Walker [
You need the ordinal or name of the Summary structure which you must get, again, by GetProcAddress(). If this is not your own dll (I assume not) then either use the documentation or Dependency Walker[^] to get the relevant details.


这篇关于从dll导入结构(非托管到Win32控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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