title: Mismatch of data type when passing argument
body: <p>I am currently facing following problem. I have searched for any solution but could not find anything useful related to my problem.</p>
  
  <p>I want to use VBA to provide some parameters to a self-written DLL which is going to calculate a result for me.</p>
  
  <p>My problem: As soon as I try to process the values passed to the function <strong>setCEPCI</strong> I get an "Microsoft Excel has stopped working"- error(no further details). If I put those three lines (see my copied code) in comments, however, everything is working fine. I tried a lot of workarounds but it all came down to those lines.
  Surprisingly, I can use the passed arguments in the first function <strong>getPEC</strong>, where e.g. <strong>x</strong> is my <strong>outflow</strong>.</p>
  
  <p>For the record I am using a def file for exporting the function, though, IMHO the error seems to be some mismatch of data types.</p>
  
  <p><strong>EDIT: For clarification: If my DLL is not found e.g. I get the same Microsoft-Excel-error due to the RV assignment. If I try to assign any value to RV in the first function, I also get that error. On the other hand I can assign any value to PEC without problems.</strong></p>
  
  <p>My DLL looks like:</p>
  
  <pre><code>extern "C" {
  
  
  
  typedef void(CALLBACK * FncPtrClssGetCEPCI)(CEPCIvalues &amp;, int, int, int &amp;);
  
  double PEC_backUp;
  const int numbMaxCEPCIlistMembers = 3;
  CEPCIvalues cepcilist_backUp[numbMaxCEPCIlistMembers];
  
  void __stdcall getPEC(int typeOfPump, double outflow, double &amp;PEC, int &amp;RV)
  {
      //y = a x^6 + b x^5 + c x^4 + d x^3 + e x^2 + f x^1 + g x^0
      if ((typeOfPump &lt; 1) || (10 &lt; typeOfPump)) {
          RV = -1;
          return;
      }
      double a, b, c, d, e, f, g;
  //...
      PEC_backUp = a * pow(outflow, 6.0) +
          b * pow(outflow, 5.0) +
          c * pow(outflow, 4.0) +
          d * pow(outflow, 3.0) +
          e * pow(outflow, 2.0) +
          f * pow(outflow, 1.0) +
          g * pow(outflow, 0.0);
  
  
      double EUR_USD_07_2000 = 0.939082609;
      PEC_backUp = PEC_backUp / EUR_USD_07_2000;
      PEC = PEC_backUp;
  }
  
  void __stdcall setCEPCI(int monthIN, int yearIN, int &amp;RV)
  {
      //HINSTANCE hinstCEPCI = LoadLibraryEx("CEPCI.dll", NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR);
      HINSTANCE hinstCEPCI = LoadLibrary("C:\\Users\\...somePath...\\CEPCI.dll");
      if (!hinstCEPCI)
      {
          RV = -11;
          return;
      }
      FncPtrClssGetCEPCI ptrGetCEPCI = (FncPtrClssGetCEPCI)GetProcAddress(hinstCEPCI, "getCEPCI");
      if (!ptrGetCEPCI)
      {
          RV = -22;
          return;
      }
      //CEPCI values of 13/1970 and 07/2000 are automatically extracted
      //due to less interaction and, thus, risk of errors in user input
  
      int monthIN_auto = 13;
      int yearIN_auto = 1970;
      ptrGetCEPCI(cepcilist_backUp[0], monthIN_auto, yearIN_auto, RV);
      monthIN_auto = 7;
      yearIN_auto = 2000;
      ptrGetCEPCI(cepcilist_backUp[1], monthIN_auto, yearIN_auto, RV);
      //now extract CEPCI value of user specific input
  
  
  
  
    //  monthIN_auto = monthIN;
  
    //  yearIN_auto = yearIN;
  
  
      ptrGetCEPCI(cepcilist_backUp[2], monthIN_auto, yearIN_auto, RV);
          CEPCIvalues cepcilist;
          cepcilist = cepcilist_backUp[2];
  
  
  
  
  
  // RV = monthIN + yearIN;
  
      ptrGetCEPCI = 0;
      FreeLibrary(hinstCEPCI);
      hinstCEPCI = 0;
      return;
  }
  </code></pre>
  
  <p>My VBA code looks like:</p>
  
  <pre><code>Public Declare Sub getPEC _
  Lib "C:\Users\...somePath...\OPunit0011PUMP.dll" _
  (ByVal typeOfPump As Integer, ByVal outflow As Double, ByRef PEC As Double, ByRef RV As Integer)
  
  Public Declare Sub setCEPCI _
  Lib "C:\Users\...somePath...\OPunit0011PUMP.dll" _
  (ByVal monthIN As Integer, ByVal yearIN As Integer, ByRef RV As Integer)
  
  
  Function CallPump()
  
  Dim typeOfPump, RV, monthIN, yearIN As Integer
  typeOfPump = 9
  Dim outlfow, PEC As Double
  outflow = 100
  monthIN = 5
  yearIN = 2008
  
  Call getPEC(typeOfPump, outflow, PEC, RV)
  
  Call setCEPCI(monthIN, yearIN, RV)
  
  
  
  
  End Function
  </code></pre>
  
  <p>Any help is appreciated. Thank you in advance.</p>