传递参数时数据类型不匹配

时间:2015-09-02 13:28:11

标签: c++ excel vba types

我目前面临以下问题。我搜索过任何解决方案,但找不到与我的问题相关的任何有用的东西。

我想使用VBA为自编写的DLL提供一些参数,这些DLL将为我计算结果。

我的问题:当我尝试处理传递给函数 setCEPCI 的值时,我得到“Microsoft Excel已停止工作” - 错误(没有进一步的细节)。但是,如果我在评论中放置这三行(请参阅我复制的代码),一切正常。我尝试了很多变通方法,但这一切都归结为那些方面。 令人惊讶的是,我可以在第一个函数 getPEC 中使用传递的参数,例如 x 是我的流出

对于记录我使用def文件导出函数,但是,恕我直言,错误似乎是数据类型的一些不匹配。

编辑:澄清:如果找不到我的DLL,例如由于RV分配,我得到了相同的Microsoft-Excel错误。如果我尝试在第一个函数中为RV分配任何值,我也会得到该错误。另一方面,我可以毫无问题地为PEC分配任何值。

我的DLL看起来像:

   #first{
    --background:black;
    text-align:left;
    width:100px;
    height:100px;
    float:left;
    color:orange;
   }
   #second{
    --background:orange;
    text-align:center;
    width:100px;
    height:100px;
    float:left;
    color:blue;
    margin-left:20px;
   }
   #third{
    --background:blue;
    text-align:right;
    width:100px;
    height:100px;
    float:left;
    color:orange;
    margin-left:20px;
   }

我的VBA代码如下:

extern "C" {



typedef void(CALLBACK * FncPtrClssGetCEPCI)(CEPCIvalues &, int, int, int &);

double PEC_backUp;
const int numbMaxCEPCIlistMembers = 3;
CEPCIvalues cepcilist_backUp[numbMaxCEPCIlistMembers];

void __stdcall getPEC(int typeOfPump, double outflow, double &PEC, int &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 < 1) || (10 < 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 &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;
}

感谢任何帮助。提前谢谢。

1 个答案:

答案 0 :(得分:0)

我想我解决了我的问题。

查看VBA代码

Dim typeOfPump, RV, monthIN, yearIN as Integer

由于任何原因声明只将typeOfPump声明为整数,其余的(当使用Excel的实现监视功能进行监视时)仍然是变体。写

Dim typeOfPump as Integer
Dim RV as Integer
...

似乎解决了这个问题。不幸的是,我无法解释第一行的问题。

相关问题