1
我有一个C++函数,我在Excel 2013通过与VC2013内置一个DLL使用:如何通过DLL函数的参数将变量返回给Excel?
double my_function(double input) {
//do something
return input*input;
}
在Excel VBA我有这个功能是这样的:
Declare Function my_function Lib "DLL_with_my_function.dll" (ByVal input As Double) As Double
这种运作良好,到目前为止,但是,现在,我希望能够通过第二个参数返回第二条信息,说错误代码。理想情况下,此错误代码可以输出到Excel中的单元格,或者至少通过debug.print输出到控制台。我被困在使整个事情工作,并有多次Excel崩溃。这是我徒劳的尝试:
double my_function(double input, long *error_code) {
*error_code = 5;
return input*input;
}
#in Excel:
Declare Function my_function Lib "DLL_with_my_function.dll" (ByVal input As Double, ByRef error_code as long) As Double
当我打电话从工作表中的功能和指示细胞作为第二个参数的Excel崩溃我。什么是正确的,优雅的方式来做到这一点?