title: CreateInstance Returns "The specified module could not be found."
body: <p>I've been trying to get a program that worked on <code>Windows 2000</code> to work on <code>Windows 2003</code>.  Everything I've had to do so far to get the program to work on <code>Windows 2003</code> has had to do with incorrect configuration.  Right now, this piece of code:</p>
  <pre><code>chr = pAdapterEnvPtr.CreateInstance(__uuidof(PFADAPTERMNGLib::PFAdapterEnv));
  </code></pre>
  <p>is returning:</p>
  <pre><code>0x8007007E
  </code></pre>
  <p>or in other words:</p>
  <pre><code>The specified module could not be found.
  </code></pre>
  <p>I have two other programs and another .dll and I can successfully create instances of those classes.  But this seems to fail.</p>
  <p>I have used <code>Procmon</code> to try to figure out what the program can't find, but <code>Procmon</code> did not display anything that could indicate that the program could not find something.</p>
  <p>In <code>OleView</code>, if I try to create an instance of the class, I see the following image:</p>
  <p><a href="https://i.stack.imgur.com/KMxu6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KMxu6.png" alt="IClassFactory::CreateInstance failed.  The specified module could not be found.  severity: SEVERITY_ERROR, facility: FACILITY_WIN32 ($8007007E" /></a></p>
  
  <p>If you look on the left side of the image, trying to create an instance of <code>PFComgMng</code> gives me the same error.  (<code>PFAdapterEnv</code> and <code>PFCompMng</code> use the same process, <code>PFAdapterMng.exe</code>.)  However, <code>PFMQMonitor</code>, <code>PFSend</code>, and <code>PFTrace</code> all work correctly.  (Which use <code>PFMQListen.exe</code>, <code>PFSend.dll</code>, and <code>PFTraceService.exe</code>.)</p>
  <p>Another thing that I wanted to note is that the following piece of code:</p>
  <pre><code>hr = pPFCompMng.CreateInstance(__uuidof(PFADAPTERMNGLib::PFCompMng));
  </code></pre>
  <p>works perfectly fine when it gets called earlier from <code>PFAdapterMng.exe</code>.  So it seems like <code>PFAdapterMng.exe</code> can successfully find the module and create the instance, but any other processes that try to create either of the instances of the classes within <code>PFAdapterMng.exe</code> can't find the module, resulting in this error.</p>
  <p>Since <code>Procmon</code> isn't helping with this specific case, does anyone know what I could do to figure out what's keeping other processes from finding the module?</p>
  <p>UPDATE:</p>
  <p>I can't run <code>Dependency Walker</code> with profiling because <code>PFAdapterMng.exe</code> and <code>PFTraceService.exe</code> must be run as services.  I tried to run <code>Dependency Walker</code> while profiling <code>OleView</code> and tried to create instances of <code>PFAdapterEnv</code> and <code>PFCompMng</code> to try to find out why I was getting the <code>Module not found</code> message box.  Unfortunately, <code>Dependency Walker</code> didn't show that anything was missing.</p>
  <p>UPDATE2:</p>
  <p>Maybe I missed something in the <code>Procmon</code> log, so I created a new log by capturing events right before I stepped over the call to <code>CreateInstance</code> and right after the call.  Maybe someone else could take a look and tell me if i missed it?  I simply can't find any indications that <code>PFMQListen.exe</code> could not find something..</p>
  <p>Here's a link to a zipped folder with a <code>Procmon</code> file, a <code>.csv</code> file, and a <code>.xml</code> file.</p>
  <p><a href="http://www.mediafire.com/?07jq8zj7emmpsvd" rel="nofollow noreferrer">http://www.mediafire.com/?07jq8zj7emmpsvd</a></p>
  <p>UPDATE3:</p>
  <p>So, I managed to get <code>Dependency Walker</code> running under Profile mode to create an instance of <code>PFAdapterEnv</code>.  <code>Dependency Walker</code> did not find any missing <code>.dll</code>'s.</p>
  <p>So, <code>Procmon</code> doesn't show anything, and neither does <code>Dependency Walker</code>.  I was stepping through the code at the assembly level with <code>ollydbg</code>, and I noticed that the error was created in the function <code>NdrClientCall2</code>.  I don't know if this means anything.</p>
  <p>Any ideas as to what else I can try?  Do people need more information to help me solve this problem?  If so, please ask.</p>
  <p>UPDATE4:</p>
  <p>I tried using <code>/RegServer</code> to register the applications, and it worked.  I tried using <code>/RegServer</code> previously, where I just unregistered everything using <code>/UnregServer</code>.  This time, I also deleted the component from <code>Component Services</code> which I needed to have because I wanted to run <code>PFAdapterMng</code> under another identity.</p>
  <p>So, it seems like everything works when running on <code>/RegServer</code> and double-clicking the applications.  However, I would like everything to run under a different configuration.</p>
  <p>How do I configure everything to get the applications to work as follows:</p>
  <p><code>PFAdapterMng.exe</code> - Register as <code>/Service</code> and run under another identity through <code>services.msc</code>
  <code>PFTraceServer.exe</code> - Register as <code>/Service</code> and run under another identity through <code>services.msc</code></p>
  <p><code>PFMQListen.exe</code> - Register as <code>/RegServer</code> which will be started by <code>PFAdapterMng</code>
  <code>PFMQSend.dll</code> - Registered with <code>Regsvr32</code> and loaded by <code>PFAdapterMng</code></p>
  <p>Thanks,
  Krzys</p>