title: Calling C DLL from Visual Basic 6: Double data type not working
body: <p>I'm passing a simple user-defined type (UDT) from Visual Basic 6 to a C DLL. It works fine, except for the <strong>double</strong> data type, which shows up as 0.</p>
  
  <p><strong>C DLL:</strong></p>
  
  <pre><code>#define WIN32_LEAN_AND_MEAN
  
  #include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;
  
  typedef struct _UserDefinedType
  {
      signed int      Integer;
      unsigned char   Byte;
      float           Float;
      double          Double;
  } UserDefinedType;
  
  int __stdcall Initialize ( void );
  int __stdcall SetUDT ( UserDefinedType * UDT );
  
  BOOL WINAPI DllMain ( HINSTANCE Instance, DWORD Reason, LPVOID Reserved )
  {
      return TRUE;
  }
  
  int __stdcall Initialize ( void )
  {
      return 1;
  }
  
  int __stdcall SetUDT ( UserDefinedType * UDT )
  {
      UDT-&gt;Byte = 255;
      UDT-&gt;Double = 25;
      UDT-&gt;Float = 12345.12;
      UDT-&gt;Integer = 1;
  
      return 1;
  }
  </code></pre>
  
  <p><strong>Visual Basic 6 code:</strong></p>
  
  <pre><code>Option Explicit
  
  Private Type UserDefinedType
      lonInteger As Long
      bytByte As Byte
      sinFloat As Single
      dblDouble As Double
  End Type
  
  Private Declare Function Initialize Lib "C:\VBCDLL.dll" () As Long
  Private Declare Function SetUDT Lib "C:\VBCDLL.dll" (ByRef UDT As UserDefinedType) As Long
  
  Private Sub Form_Load()
  
      Dim lonReturn As Long, UDT As UserDefinedType
  
      lonReturn = SetUDT(UDT)
  
      Debug.Print "VBCDLL.SetUDT() = " &amp; CStr(lonReturn)
  
      With UDT
          Debug.Print , "Integer:", CStr(.lonInteger)
          Debug.Print , "Byte:", CStr(.bytByte)
          Debug.Print , "Float:", CStr(.sinFloat)
          Debug.Print , "Double:", CStr(.dblDouble)
      End With
  
  End Sub
  </code></pre>
  
  <p><strong>The output from Visual Basic:</strong></p>
  
  <pre><code>VBCDLL.SetUDT() = 1
                Integer:      1
                Byte:         255
                Float:        12345.12
                Double:       0
  </code></pre>
  
  <p>As you can see, the double is appearing as <strong>0</strong>, when it should be <strong>25</strong>.</p>