title: How can I "start" a DLL like an executable at runtime?
body: <p>I want to write a very, very small program that parses the launch arguments and chooses one of several DLLs to "boot into."</p>
  
  <p>I've already written an application that I'd like to "run" as a DLL by writing it as an application, then changing the Visual Studio project properties to build it as a DLL instead. I know I need to use LoadLibrary and GetProcAddress in concert to get the functionality I want, but I'm having trouble finding clear and comprehensive documentation on this, as a lot of the use cases aren't really of this nature. Also, I have to go this route based on the project and platform restrictions. </p>
  
  <p>I found <a href="https://msdn.microsoft.com/en-us/library/ms810279.aspx" rel="nofollow noreferrer">this page</a>, which has some information, but it's not clear enough for me to adapt for my purposes.</p>
  
  <p>Edit: Here's where I'm at right now.</p>
  
  <p>I have a DLL project whose main function signature looks something like this:</p>
  
  <pre><code>__declspec(dllexport) int cdecl main(int argc, char *argv[])
  </code></pre>
  
  <p>I also have an application project whose attempt at loading the DLL and running the above function looks like this:</p>
  
  <p><code>typedef int (CALLBACK* LPFNDLLFUNC1)(int, char *);</code></p>
  
  <p>...</p>
  
  <pre><code>        HMODULE dllHandle = NULL;
          BOOL freeResult, runTimeLinkSuccess = FALSE;
          LPFNDLLFUNC1 lpfnDllFunc1;    // Function pointer  
          if (args-&gt;IsEmpty())
          {
              dllHandle = LoadLibrary(L"TrueApplication.dll");
              if (NULL != dllHandle)
              {
                  lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(dllHandle, "main");
                  if (lpfnDllFunc1)
                  {
                      int retVal = lpfnDllFunc1(0, "1");
                  }
  </code></pre>
  
  <p>Currently, the LoadLibrary call works, but not GetProcAddress. </p>