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崩潰我。什麼是正確的,優雅的方式來做到這一點?