Setting SDL memory-related Requirements before your Application Startshttp://blogs.msdn.com/b/sdl/archive/2009/08/06/setting-sdl-memory-related-requirements-before-your-application-starts.aspxHello, Michael here.
A word of warning, this is purely an “FYI” post that has very little to do with SDL policy!
I get this question, “How do I call various SDL-mandated APIs before my code starts?” about once a month, so I decided to write abouten-USTelligent Evolution Platform Developer Build (Build: 5.6.50428.7875)re: Setting SDL memory-related Requirements before your Application Startshttp://blogs.msdn.com/b/sdl/archive/2009/08/06/setting-sdl-memory-related-requirements-before-your-application-starts.aspx#9859702Fri, 07 Aug 2009 02:49:03 GMT91d46819-8472-40ad-a661-2c78acb4018c:9859702david_leblanc<p>You're making this much too hard. Very interesting trick, but here's the easy way:</p>
<p>#include &lt;stdio.h&gt;</p>
<p>class PreInit</p>
<p>{</p>
<p> &nbsp;public:</p>
<p> &nbsp;PreInit() { printf(&quot;PreInit constructor\n&quot;); }</p>
<p>};</p>
<p>static PreInit pre;</p>
<p>int main(void)</p>
<p>{</p>
<p> &nbsp;printf(&quot;Main running\n&quot;);</p>
<p> &nbsp;return 0;</p>
<p>}</p>
<p>And the results:</p>
<p>c:\scratch&gt;starts</p>
<p>PreInit constructor</p>
<p>Main running</p>
<p>Conversely, if you have to do some cleanup only after main (or DllMain for that matter), make a static class that does the cleanup in the destructor.</p>
<p>Yet another easy approach if you have a DLL that your class loads is to put this in the DLL initialization.</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9859702" width="1" height="1">