Cannot convert two digit-long integer to std::string
I'm dealing with some DLLs that I'm trying to call from Excel.
The issue is that, depending on how I call from VBA the DLL then it works or it does not:
Here's the c++ code:
And here's the VBA code:
BSTR test_int2str(double x)
s << x;
BSTR string2bstr(string input_string)
const size_t len = input_string.length();
return SysAllocStringByteLen(input_string.c_str(), len);
The thing is:
Declare Function test_int2str Lib _
(ByVal x As Double) As String
Function test_int2str_wrap(x As Double) As String
Dim test_string As String
test_string = test_int2str(x)
test_int2str_wrap = test_string
If I do in Excel ...
=test_int2str(1) => result="1"
=test_int2str(9) => result="9"
=test_int2str(10) => result="〱"
=test_int2str(11) => result "ㄱ"
=test_int2str(109) => result="〱9"
=test_int2str(111) => result="ㄱ1"
So, you see, it's a curious behavior. It does work well with one-digit-long numbers, but it does not with longer ones ...
However, if I do call the 2nd function in VBA (test_int2str_wrap) everything works just perfect ...
=test_int2str(111) => result="111" ...
I know the 2nd way works, but I'd like to skip that way: I'd like to use VBA as less as possible...