传递参数时数据类型不匹配
Mismatch of data type when passing argument
我目前面临以下问题:我已经寻找了任何解决方案,但没有找到任何有用的有关我的问题。
我想使用VBA为自己编写的DLL提供一些参数,该DLL将为我计算结果。
我的问题:只要我尝试处理传递给函数setCEPCI的值,我就会得到"Microsoft Excel已停止工作"-错误(没有进一步的细节)。但是,如果我将这三行(请参阅我复制的代码)放在注释中,则一切正常。我尝试了很多变通方法,但最终都归结为这几行。令人惊讶的是,我可以在第一个函数getPEC中使用传递的参数,例如x是我的流出。
为了记录,我使用def文件导出函数,虽然,恕我冒昧,错误似乎是数据类型的一些不匹配。
编辑:澄清:如果我的DLL没有找到,例如,由于RV分配,我得到相同的microsoft - excel错误。如果我尝试在第一个函数中给RV赋任何值,我也会得到那个错误。另一方面,我可以将任何值赋给PEC而不会出现问题。
我的DLL看起来像:
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;
}
我的VBA代码看起来像:
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
任何帮助都是感激的。
我想我的问题解决了。
查看VBA代码
Dim typeOfPump, RV, monthIN, yearIN as Integer
出于某种原因仅将typeOfPump声明为整数,其余的(在使用Excel实现的监视函数进行监视时)仍然是可变的。写
Dim typeOfPump as Integer
Dim RV as Integer
...
似乎能解决问题。遗憾的是,我无法解释第一行的问题
相关文章:
- 将 unordered_map 与 Catch2 谓词一起使用时类型不匹配
- 重载函数的地址与所需类型不匹配
- 参数错误可能与类型不匹配有关?
- 调用子例程时类型不匹配
- POSIX(C )参数类型不匹配
- typedef 类型不匹配,将其传递到函数中
- 为什么此代码编译 (C++11) 而没有类型不匹配错误
- 候选模板被忽略:推断的类型与调整后的类型不匹配
- 内联 ASM:'out'的操作数类型不匹配
- 为什么我们有一个类型不匹配
- 解析一般CSV读取功能时,如何处理不同的数据类型?(不明确指定它们)
- C++类和freeglut(参数类型不匹配)
- 警告 639:二进制操作中类型 'uint64' 的强类型不匹配
- 警告 634:相等或有条件的强类型不匹配(类型"bool")
- 不了解C++类型不匹配:const Foo* to Foo* const&
- 函数声明和定义的返回类型不匹配,编译器可以吗?
- 类型不匹配
- 传递参数时数据类型不匹配
- openCV警告组件数据类型不匹配
- 函数调用中的数据类型不匹配