2

私のアプリケーションは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 ;

}
4

1 に答える 1

0

#pragma pack(1) で構造体をパックします

于 2013-12-20T09:37:48.923 に答える