I've a COM 64-bit dll built with Windows 2003 SP1 SDK April 2005
edition on Windows XP SP2. All MIDL options and project settings are
done correctly (as far as i know) to build the 64-bit DLL.
This DLL defines a structure of the form
typedef struct sVALIDATION
{
UINT32 unDataLen;
BYTE *pData;
}S_VALIDATION;
and has an interface method to fill up this structure of the form:
HRESULT FillUpStructure([in,out,ptr]S_VALIDATION *pSValidation);
{
//pseudo code
pSValidation->unDataLen = 3;
pSValidation->pData = (BYTE *)CoTaskMemAlloc(3);
//... set bytes
}
Now I'm using the tlb generated above, in my client application and
calling the FillUp method
//pseudo code
#import COM64.tlb
using namespace COM64Lib;
void main()
{
S_VALIDATION sValid;
memset(&sValid,0,sizeof(sValid));
try
{
IValidationPtr pValidation =
IValidationPtr(__uuidof(ValidationClass));
//....
pValidation->FillUpStructure(&sValid);
wprintf(L"%d",sValid.unDataLen); // prints "3" correctly
wprintf(L"%X",sValid.pData[0]); //throw up here
}
catch(...)
{
//....
}
//cleanup code
}
QUESTION:
When I'm accessing the pData value, it is throwing error. I debugged on
XP x64 machine and noticed
that pData pointer occupies 8 bytes. But when it returns from the
method call, the higher 4 bytes are being set
so the client code ends up accessing value at [00a1308e'00000000]
instead of [00000000'00a1308e] where actual data is present.
pData pointer before the call as seen in memory window {00 00 00 00 00
00 00 00}
pData pointer after the call as seen in memory window {00 00 00 00 8e
30 a1 00}
Why is it happening this way? I started stepping through code and went
little deep where RPCRT4!.... module doing some unmarshalling stuff.. I
didn't understand this part and quit. Please help me.
Thanks in advance,
Vedala