Cannot convert two digit-long integer to std::string
Hi everyone:
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:
Code:
BSTR test_int2str(double x)
{
string mystring;
ostringstream s;
s << x;
mystring=s.str();
return string2bstr(mystring);
}
BSTR string2bstr(string input_string)
{
const size_t len = input_string.length();
return SysAllocStringByteLen(input_string.c_str(), len);
}
And here's the VBA code:
Code:
Declare Function test_int2str Lib _
"d:\datos\doc\tech\c++\excel\ipfnc_dll\ipfnc.dll" _
(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
End Function
The thing is:
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...
Any ideas?
Thanks!
Lucas