title: Creating DLLs in C++
body: <p>This is a follow-up question to <a href="https://stackoverflow.com/questions/4829962/use-c-dll-with-vb6">this question</a> because I'm losing my mind over this right now.</p>
  
  <p>Someone pointed me to <a href="http://vb.mvps.org/tips/vb5dll.asp" rel="nofollow noreferrer">this article</a> and I'm trying to copy section 4 from there.</p>
  
  <p>So I created an empty C++ Project in MSVC++2010, created a new .cpp file inside it, and put the following code in there:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #define CCONV _declspec(dllexport) // used to be __stdcall but resulting DLL is identical
  
  int CALLBACK LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize,
  LPSTR lpszCmdLine)
  {
       return 1;
  }
  
  short CCONV PassInteger (short intgr, short far *pintgr)
  {
      *pintgr = intgr;
      return intgr + 1;
  }
  </code></pre>
  
  <p>(I got the <code>LibMain</code> code from <a href="http://support.microsoft.com/kb/106553/en-us" rel="nofollow noreferrer">here</a> but I think it doesn't do anything here.)</p>
  
  <p>Then, I added a .def file to the project and put this in it:</p>
  
  <pre><code>;vb6dll32 DEF File
  LIBRARY vb6dll32
  
  CODE PRELOAD MOVEABLE DISCARDABLE
  DATA PRELOAD MOVEABLE
  
  EXPORTS
  PassInteger
  </code></pre>
  
  <p>The compiler outputs two warnings that <code>CODE</code> and <code>DATA</code> in the .def file are not supported for the current target, but it eventually compiles and generates the file <code>vb6dll32.dll</code> which I have then copied to <code>C:\windows\system</code> and <code>...\system32</code> and <code>C:\</code>.</p>
  
  <p>Then I have created a VB6 project, put a button into the form and added this sourcecode:</p>
  
  <pre><code>Private Declare Function PassInteger Lib "vb6dll32.dll" _
  (ByVal intgr As Integer, pintgr As Integer) As Integer
  
  Private Function BuiltIntest() As Integer
  
      Dim i As Integer
      Dim ir As Integer
  
      i = 7
  
      i = PassInteger(i, ir)
      Print i, ir
  
      Return
  
  End Function
  
  Private Sub Command1_Click()
      MsgBox (BuiltIntest())
  End Sub
  </code></pre>
  
  <p>Now, when I click the button, it still gives me "Runtime error '53': file vb6dll32.dll not found." (This happens even if I give it a fully specified path in the VB source code, e.g. "C:\vb6dll32.dll" and the file is definitely there. I tried giving its location without path and without ".dll" and so on, nothing changes.)</p>
  
  <p>What also bugs me is, when I run <code>regsvr32 c:\vb6dll32.dll</code> it also tells me "The module C:\vb6dll32.dll could not be loaded. etc etc" .. I have no idea what it should do but that should generally do something for DLL files, right?</p>
  
  <p>What am I doing wrong?! Thanks for your help.</p>