I have something here im not entirely sure what it means, perhaps someone WiZe AnD pOwErFuL can explain this to me ;)

Im working on some new speech recognition stuff, and am using my old examples as a starting point (search COM section if interested). The Coffee2 example works, and thats how i posted it.

However there turns out to be a nasty bug in it, which never showed itself, cause it was cancelled out by another nasty bug!! (The beauty of coding COM type lib translations by hand ~ this was obviously before Jaheth's COMView tool ;) )

The big bug was the how i defined a variant structure for the origional source. I screwed up and made two of the Reserved entries DWORDS, instead of WORDS!. The other bug, that null'd this was my hand translation of C++ structures. I was oversizing SIGNED CHAR's in a couple of structures, and by some wicked chance of luck, the variants aligned in memory just right, such that i never noticed this. (CAN YOU BELIEVE THAT!).

Now, on my receint work, i cut out the old definition i made for a Variant, and used Japheth's definition (Its been well tested in practice). Doing so made all this stuff come to the surface. Using Japheth's COMView, i also peeked into the typelib for its translation of these structure, and this is how i saw by SBYTE bugs in my hand translations.

When all was corrected, it still didnt work. Even though they are all correct by definition. It wasnt until i noticed the COMView also output's a byte alignment value with the structure definition:


pszName LPVOID ?
ulId DWORD ?
ulFirstElement DWORD ?
ulCountOfElements DWORD ?
pNextSibling LPVOID ?
pFirstChild LPVOID ?
SREngineConfidence REAL4 ?
Confidence SBYTE ?

In this case, a 4 follows the STRUCT keyword. When i punched in these values in my hand translations for the structures im using, it all worked flawlessly! Now my Big question is WHY??? What purpose does this have? A Pointer returned from a method call should already be aligned by virtue of how memory is allocated for exchange of interprocess data.... So to me this is a big mystery why its doing this.

(( And another testiment to Japheth's COMView tool! I would have never tracked this down with out it! ))

If you can explain this please let me know! I never place alignment values in structure definitions, and wondering if is should start...

Thanks alot!
Posted on 2003-07-05 22:34:55 by NaN
Hi NaN,

this alignment byte in comview's structs comes directly from TYPEATTR.cbAlignment.

And AFAIK, using it in struct header may influence value returned from SIZEOF operator. So your SPPHRASERULE struct may increase by 3 bytes in size.

Posted on 2003-07-06 00:48:48 by japheth
I see what your getting at, but the part i dont understand is i get back a memory pointer from the method call. I then use the structure to give the pointer a map like template for navigating the memory pointed to. I dont see how it would affect the use of memory already recieved dynamically by another process before i use the structure at all...

This is why i called it Wierd... :me shrugs:

Posted on 2003-07-06 03:09:02 by NaN
Hey NaN,

the "alignment" parameter is only able to influence alignment of members inside the structure. So for example:

STRUCT1 struct 1
var1 db ?
var 2 dd ?
STRUCT1 ends

will result in a structure exactly as you may suppose. With

STRUCT1 struct 4
var1 db ?
var 2 dd ?
STRUCT1 ends

you will in fact get:

STRUCT1 struct 1
var1 db ?
filler db 3 dup (?)
var 2 dd ?
STRUCT1 ends

That's all.
Posted on 2003-07-06 06:37:47 by japheth
Ahhhh... I feel so stupid.. Thanks for clearing this up. A picture is worth a thousand words.. or in this case, some code ;)

Well that would explain exactly what is happening. And if I had to do future hand translations, i might want to be weary of such things before I encounter bugs that will have no hope in hell of detection... Like I said before, if it wernt due to your ComView tool, I would have never caught on to this!

Thanks again for your patience Japheth ;)
Posted on 2003-07-06 23:17:35 by NaN