Hello all,
The following (perhaps even correctly<g>) generates C++ code to print
size and structure offset information. It is not terribly useful
because it assumes that you already have the structure classes defined
(see the use of #getFieldNames), but it can help in tracking down
problems (n=1). Note that you might have to fix case problems in the
field names.
An even better trick would be to write IDL to let the type library
analyzer do the work.
Have a good one,
Bill
sizeAndOffsetForStructures:structureClasses
"Generate C++ code to find sizes and offsets; crude, but effective"
"
CodeGenerator sizeAndOffsetForStructures:( Array with:TOKEN_PRIVILEGES )
"
| out |
out := String writeStream.
out
nextPutAll:'#include <iostream>'; cr;
nextPutAll:'#include <sstream>'; cr;
nextPutAll:'#include <iomanip>'; cr;
nextPutAll:'#include <windows.h>'; cr; cr;
nextPutAll:'using namespace std;'; cr; cr;
nextPutAll:'int main(int argc, char *argv[])'; cr;
nextPutAll:'{'; cr;
tab; nextPutAll:'ostringstream out;'; cr;
tab; nextPutAll:'out'; cr.
structureClasses do:[ :structure |
out
tab; tab; nextPutAll:'<< "'; nextPutAll:structure name; nextPutAll:'"
<< endl'; cr;
tab; tab; nextPutAll:'<< "Size: " << sizeof('; nextPutAll:structure
name; nextPutAll:') << endl;'; cr.
structure getFieldNames do:[ :field |
out
tab; tab; nextPutAll:'<< "'; nextPutAll:field; nextPutAll:': " <<
offsetof('; nextPutAll:structure name; nextPut:$,; nextPutAll:field;
nextPutAll:') << endl'; cr.
].
].
out
cr;
tab; nextPutAll:'OutputDebugString(out.str().c_str());'; cr;
tab; nextPutAll:'return(0);'; cr;
nextPut:$}; cr; cr.
SmalltalkWorkspaceDocument show streamIn:out contents readStream.
--
Wilhelm K. Schwab, Ph.D.
[hidden email]