How to compile and test samples under Windows?
Adam D. Ruppe
destructionator at gmail.com
Sat Nov 9 15:37:36 PST 2013
Aaaand figured it out: actually, the fact it worked on Vista but
not on XP was the key clue and I'm ashamed I didn't realize this
earlier.
This comment hints at it too in dserver.d
// Multiple threads not supported yet
Anyway, D's thread local storage doesn't quite work right on
Windows XP, and does work beautifully on Vista and up. I don't
really know why, but that's the way it is. It can cause invalid
memory accesses...
....And the GUIDs and a couple other variables in the sample are
thread local! (Back when the sample was written, global variables
were truly global, like in C. Since then, that's changed, the
variables are now in thread local storage unless you mark them
with __gshared, which breaks things...)
So here's the fix: add __gshared to a few places.
dserver.d, line 119 give or take, there's some globals g_cObj etc:
__gshared ULONG g_cObj =0;
__gshared ULONG g_cLock=0;
__gshared HINSTANCE g_hInst;
chello.d, about line 24:
__gshared GUID CLSID_Hello = { 0x30421140, 0, 0, [0xC0, 0, 0, 0,
0, 0, 0, 0x46] };
__gshared GUID IID_IHello = { 0x00421140, 0, 0, [0xC0, 0, 0, 0,
0, 0, 0, 0x46] };
(Actually, those could probably be immutable too, but meh just
making it work.)
Then recompile, remembering the libraries we talked about on
stack overflow, and you get a new dll. On my computer, it
actually came out 100KB smaller too, cool!
Now, chello.exe runs and successfully creates the object.
regsvr32.exe still fails though, on XP (works on Vista), I must
still be missing something. But this is a lot closer already....
More information about the Digitalmars-d-learn
mailing list