View Single Post
  #4  
Old March 20th 12, 03:58 PM posted to microsoft.public.win98.gen_discussion
Lostgallifreyan
external usenet poster
 
Posts: 1,562
Default SOLVED. Was: MinGW. GCC on W98?

Lostgallifreyan wrote in
:

I have the Dev-CPP-supplied MinGW but it's older, and I need to try a
newer one because I'm exploring a file dialog API call. Code that
compiles and runs fine using TCC crashes COMDLG32.DLL when compiled by
GCC v3.4.5, even though it compiles with no errors or warnings.


In case anyone finds this in some web archive while being hit with this
problem themselves, here's the answer.

Context:
OPENFILENAME ofn;
ZeroMemory(&ofn,sizeof(ofn));

In many examples, that ZeroMemory bit is omitted. As TheForger says in his
tutorial, it is wise to include it, as some API's do not like to find unused
bits of structs containing data they shouldn't.

It turns out that TCC is polite about this, it zeros all the elements in the
OPENFILENAME struct when creating it, but GCC won't. The ONLY reason I ever
saw code compiled by GCC run at all without this (and also the reason it was
eratic and rare) is that SOMETIMES it might be lucky enough to be creating
the struct in a bit of RAM that happens to have nothing but zeros in it.

I'd still like a newer version of GCC, but I won't be relying on it to do
this. ALWAYS do ZeroMemory on a struct or array if in doubt of what might
otherwise be in there.