<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="https://mg.to" xmlns:dc="https://purl.org/dc/elements/1.1/">
<channel>
 <title>mg.to - NULL hInstance Considered Harmful - Comments</title>
 <link>https://mg.to/2004/08/12/null-hinstance-considered-harmful</link>
 <description>Comments for &quot;NULL hInstance Considered Harmful&quot;</description>
 <language>en</language>
<item>
 <title>It could be any of the reasons that you might have structured th</title>
 <link>https://mg.to/2004/08/12/null-hinstance-considered-harmful#comment-28</link>
 <description>&lt;p&gt;It could be any of the reasons that you might have structured the code as a large DLL and stub EXE in the first place. For example, you may want to make some of your code available to other apps with an in-process COM server or DLL interface.&lt;/p&gt;

&lt;p&gt;Or it may be a case like the Python interpreter, where &lt;code&gt;python.exe&lt;/code&gt; is a console app and &lt;code&gt;pythonw.exe&lt;/code&gt; is a GUI app. Each of these is a small stub that loads Python23.dll, the Python interpreter itself.&lt;/p&gt;

&lt;p&gt;Basically anything like that, where you might want to have a couple of different versions of the .exe itself but have most of the code shared between them. It could even be something as trivial as needing to run two instances of your app for different purposes but wanting them to show up with different names in Task Manager.&lt;/p&gt;</description>
 <pubDate>Thu, 12 Aug 2004 15:33:17 +0000</pubDate>
 <dc:creator>Michael Geary</dc:creator>
 <guid isPermaLink="false">comment 28 at https://mg.to</guid>
</item>
<item>
 <title>I&#039;m curious why you&#039;d want to do the conversion...</title>
 <link>https://mg.to/2004/08/12/null-hinstance-considered-harmful#comment-27</link>
 <description>&lt;p&gt;I&amp;#8217;m curious why you&amp;#8217;d want to do the conversion&amp;#8230; The only reason that comes to mind would be to implement a &amp;#8220;check for updates&amp;#8221; feature in the EXE that can replace the core of the app on the fly without file-in-use issues. Well, as I&amp;#8217;m typing this, also maybe loading a version of your app compiled for a specific OS (like a Unicode-only version). Are there any other good reasons?&lt;/p&gt;</description>
 <pubDate>Thu, 12 Aug 2004 07:15:11 +0000</pubDate>
 <dc:creator>Mike Sax</dc:creator>
 <guid isPermaLink="false">comment 27 at https://mg.to</guid>
</item>
<item>
 <title>NULL hInstance Considered Harmful</title>
 <link>https://mg.to/2004/08/12/null-hinstance-considered-harmful</link>
 <description>&lt;p&gt;On a couple of occasions, I&#039;ve converted large Windows applications from EXEs to DLLs which are loaded by stub EXEs. There are several reasons you might want to do this, and for the most part it&#039;s surprisingly easy. Most Windows code doesn&#039;t know or care if it&#039;s running in a DLL or EXE, as long as it has the right instance handle for any functions that load resources or the like.&lt;/p&gt;
&lt;p&gt;There were a few Windows functions that gave us grief, though. These are the functions that accept a NULL &lt;code&gt;hInstance&lt;/code&gt; to mean the current process. I used to think this was a nice convenience, but all the code that used a NULL &lt;code&gt;hInstance&lt;/code&gt; had to be converted to take an explicit &lt;code&gt;hInstance&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I searched for the functions that came to mind and fixed them:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/getmodulebasename.asp&quot;&gt;&lt;code&gt;GetModuleBaseName&lt;/code&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getmodulefilename.asp&quot;&gt;&lt;code&gt;GetModuleFileName&lt;/code&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getmodulehandle.asp&quot;&gt;&lt;code&gt;GetModuleHandle&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But I forgot about an entire group of functions and had to find them the hard way, through some tedious debugging:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/enumresourcelanguages.asp&quot;&gt;&lt;code&gt;EnumResourceLanguages&lt;/code&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/enumresourcenames.asp&quot;&gt;&lt;code&gt;EnumResourceNames&lt;/code&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/enumresourcetypes.asp&quot;&gt;&lt;code&gt;EnumResourceTypes&lt;/code&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/findresource.asp&quot;&gt;&lt;code&gt;FindResource&lt;/code&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/findresourceex.asp&quot;&gt;&lt;code&gt;FindResourceEx&lt;/code&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/shlwapi/version/findresourcewrapw.asp&quot;&gt;&lt;code&gt;FindResourceWrapW&lt;/code&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Resources/IntroductiontoResources/ResourceReference/ResourceFunctions/LoadResource.asp&quot;&gt;&lt;code&gt;LoadResource&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Are there more functions like this?&lt;/p&gt;
</description>
 <comments>https://mg.to/2004/08/12/null-hinstance-considered-harmful#comments</comments>
 <category domain="https://mg.to/topics/programming">Programming</category>
 <category domain="https://mg.to/topics/programming/win32.html">Win32</category>
 <pubDate>Thu, 12 Aug 2004 00:10:39 +0000</pubDate>
 <dc:creator>Michael Geary</dc:creator>
 <guid isPermaLink="false">15 at https://mg.to</guid>
</item>
</channel>
</rss>
