سؤال

In my MFC ActiveX program, there is a calling of function offered by a dll file. And there is a struct type parameter in the function. The strange thing I met is after calling the function, the data in struct is not complete. I am a newer of ActiveX and DLL, and really can't understand how can this happened... The main codes are below:

The defination of struct:

typedef struct{
    WORD m_protocol;
    WORD m_playstart;
    ...
    char url[128];
    char username[MAX_USER_NAME_LEN+1];
    char password[MAX_PASSWORD_LEN+1]; 
}CHANNEL_CLIENTINFO;

The ActiveX codes:

CHANNEL_CLIENTINFO channelInfo;
...
...
GSNET_ClientStart(&channelInfo);

The dll codes:

GSNET_ClientStart(CHANNEL_CLIENTINFO *m_pChaninfo)
{
    ...
    ...
}

Can anyone help me? Thanks all.

for more details:

In ActiveX program, before call the GSNET_ClientStart, I initialize the struct with some date. Such as the 'url':

sprintf(channelInfo.url, "192.168.121.122");

And after the calling, in dll function GSNET_ClientStart, I get out the url, it turns out to be "168.121.122", the "192." is missing.

I can make sure that I did't make any mistake in basic grammar.

هل كانت مفيدة؟

المحلول

There is a layout mismatch between the struct definitions in your two modules. It seems that the offset to the url member in your DLL has an offset of 4 more than the offset to that field in your ActiveX.

Make sure that the struct definitions match in both modules. Make sure that the compiler options relating to struct layout are the same in both modules.

I cannot give a definitive fix because there are so many ways in which this mismatch could occur, but for sure the root problem is a mismatch.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top