VC ++结构比较dll和应用程序

时间:2013-02-21 07:28:54

标签: visual-c++ dll structure

我的应用程序调用dll并使用dll结构更新应用程序结构。 但是应用程序结构中有一个额外的字段(bool enable)。

当我尝试分配我的应用程序struture.enable时,我得到了与垃圾值相同的更新。

如何检查dll中定义的结构大小和应用程序中定义的结构是否具有相同的语法。

我无法更改dll中的任何内容。

如果dll结构中不存在该字段,我希望将应用程序结构初始化为零。

我提供以下代码,

///// ** structure definition in the dll called application ** //////
typedef struct
{
    DWORD   Size;   
    bool    mode;   
    BYTE    check;  
    DWORD   time_1; 
    DWORD   time_2; 



} STR_INTERFACE;

///// ** structure definition in the application ** //////


typedef struct
{
    DWORD   Size;  
    bool    mode;  
    BYTE    check; 
    DWORD   time_1;
    DWORD   time_2;

    bool enable; 


} STR_INTERFACE;


///
///mypassedstr will conatin the updated structure pointer with the 
///structure members updated by the dll

int MY_Appli_function::Interface_1_func ( LPCTSTR name_1,  LPVOID mypassedstr )
{


    STR_INTERFACE mycodestr;
        STR_INTERFACE* mynewstr = (STR_INTERFACE*)mypassedstr;

        mycodestr.Size    = mynewstr->.Size   ;
        mycodestr.mode    = mynewstr->.mode   ;
        mycodestr.check   = mynewstr->.check  ;
        mycodestr.time_1  = mynewstr->.time_1 ;
        mycodestr.time_2  = mynewstr->.time_2 ;
        mycodestr.enable  = mynewstr->.enable ;

}

1 个答案:

答案 0 :(得分:0)

使用#pragma pack(1)

打包您的结构
相关问题