Has anybody out there ever managed to do this successfully ?
I've tried a number of variations along the following lines but no success:-
BSTR _stdcall atest (int a)
{
CString out;
if (a > 100) out = "a is greater than 100"; else
out = "a is less that 101";
BSTR bout = out.AllocSysString();
return(bout);
}
If you Declare atest as function in VB excel and place a reference to the function in a cell No problem it works oK. If you try calling the function from a Visual Basic subroutine the function returns the first letter of the output string only (ie the letter 'a').
I remember reading that VB assumes strings returned from DLLS to be ANSI and automtically converts them to unicode
presumeably by interleaving NUL characters. This behaviour might account for premature truncation of the string (ie 2 Nuls in a row = a unicode Nul). If this really is the problem does anyone know how to create, allocate and return a BSTR in ansi????
I've tried a number of variations along the following lines but no success:-
BSTR _stdcall atest (int a)
{
CString out;
if (a > 100) out = "a is greater than 100"; else
out = "a is less that 101";
BSTR bout = out.AllocSysString();
return(bout);
}
If you Declare atest as function in VB excel and place a reference to the function in a cell No problem it works oK. If you try calling the function from a Visual Basic subroutine the function returns the first letter of the output string only (ie the letter 'a').
I remember reading that VB assumes strings returned from DLLS to be ANSI and automtically converts them to unicode
presumeably by interleaving NUL characters. This behaviour might account for premature truncation of the string (ie 2 Nuls in a row = a unicode Nul). If this really is the problem does anyone know how to create, allocate and return a BSTR in ansi????