Page 1 of 1

EXCEPINFO structure under Win 64

Posted: Thu May 28, 2009 10:40 pm
by srod
Hi,

I am aiming this at anyone who may have the Windows 64-bit sdk and can possibly rummage through the relevant header file(s) to clear this up for me! :)

In getting COMatePLUS to work with PB 64 (which now seems to be working!) I have run up against a structure which the PB compiler does not recognise.

The structure in question (EXCEPINFO) is detailed on MSDN : http://msdn.microsoft.com/en-us/library/ms221133.aspx

Now, with PB x86 I have been using the following without problems :

Code: Select all

Structure EXCEPINFO
  wCode.w
  wReserved.w
  bstrSource.i 
  bstrDescription.i
  bstrHelpFile.i
  dwHelpContext.l
  pvReserved.i
  *pfnDeferredFillIn.i
  scode.l
EndStructure
Under PB 64, however, this caused some very hard to find bugs with COMatePLUS and being unable to find any information on the web as to how this structure should look under win 64, a process of trial and error led me to adjust the 'wReserved' field to be 6 bytes.

At the very least this suggests the addition of an additional field after 'wReserved' or perhaps that the first two fields should be 4 bytes long under win 64.

I am thus using the following version which allows COMatePLUS to run fine (with regards to this structure) with both PB 32 and PB 64 :

Code: Select all

Structure EXCEPINFO
  wCode.i
  bstrSource.i
  bstrDescription.i
  bstrHelpFile.i
  dwHelpContext.l
  pvReserved.i
  *pfnDeferredFillIn.i
  scode.l
EndStructure
I have confirmed that this structure is functioning correctly with both versions of COMatePLUS.

If someone could have a look in the Oleauto.h header file in the 64-bit sdk then I would be grateful. (I assume that this structure will be in this particular header!) My version of Vista 64 is not yet up and running sufficiently well for me to consider downloading the full sdk just yet! :)


@Fred : can we add this structure to Purebasic please? At least once we have the correct definition for both x86 and x64.

Posted: Thu May 28, 2009 10:47 pm
by Fred
IMHO, the correct structure should look like this:

Code: Select all

Structure EXCEPINFO
  wCode.w
  wReserved.w
  pad.b[4] ; Only on x64
  bstrSource.i
  bstrDescription.i
  bstrHelpFile.i
  dwHelpContext.l
  pvReserved.i
  *pfnDeferredFillIn.i
  scode.l
  pad2.b[4] ; Only on x64
EndStructure
The rules of structure alignment are a bit tricky, but basically, every 8 byte structure member must be 8 bytes aligned. And the whole structure has to be 8 byte boundary. Could you test this structure ?

Posted: Thu May 28, 2009 10:54 pm
by srod
Yes that works fine under PB 64 Fred. I was just seeking one structure which I could use in a single source for use with COMatePLUS x86 and COMatePLUS x64 rather than have to define two separate structures etc.

Still, if this can be added to PB (without the padding of course for PB x86) then COMatePLUS can dispense with its own versions completely! :wink:

Thanks.

**EDIT : what about the dwHelpContext field which is 32-bit ?

Posted: Thu May 28, 2009 10:56 pm
by ts-soft
Add a compilerdirective to the structure?

Posted: Thu May 28, 2009 10:58 pm
by freak
> **EDIT : what about the dwHelpContext field which is 32-bit ?

It needs padding too.

Posted: Thu May 28, 2009 10:59 pm
by srod
Can I just make that an integer type?

Posted: Thu May 28, 2009 11:08 pm
by freak
> Can I just make that an integer type?

No, because then your program will read the padding bytes as part of the value which can lead to a big mess if the memory wasn't 0-initialized.

Btw, i just verified it with a 64bit C compiler: The structure size must be 64byte, so with the alignment in the 3 places things should be correct.

Posted: Thu May 28, 2009 11:12 pm
by srod
freak wrote:No, because then your program will read the padding bytes as part of the value which can lead to a big mess if the memory wasn't 0-initialized.
Good point!

I shall add additional padding el-pronto!

Thanks Freak / Fred. :)