I'm write Excel 2007/2010 XLL using Excel 2007 XLL SDK in VS 2010. My function can return varios strings:
__declspec(dllexport) LPXLOPER12 WINAPI PTstate (double P, double T)
{
static XLOPER12 xResult;
xResult.xltype = xltypeStr;
debugPrintf("P = %d\n", P);
debugPrintf("T = %d\n", T);
Calculate(P, T);
Reg = GetRegion(DV.p, DV.t);
xResult.val.str = L"";
if (Reg == 0) {xResult.val.str = L"\027Ошибка диапазона параметров";debugPrintf("Reg = 0");}
if (Reg == 1) {xResult.val.str = L"\004Вода";debugPrintf("Reg = 1");}
if (Reg == 2) {xResult.val.str = L"\014Перегретый пар";debugPrintf("Reg = 2");}
if (Reg == 3) {xResult.val.str = L"\017Критическая смесь";debugPrintf("Reg = 3");}
if (Reg == 4) {xResult.val.str = L"\014Насыщенный пар";debugPrintf("Reg = 4");}
if (Reg == 5) {xResult.val.str = L"\019Сверхперегретый пар";debugPrintf("Reg = 5");}
if (Reg != 0) MathVater();
return(LPXLOPER12) &xResult;
}
When string values return to excel it's value - 'Ошибка диапазона параме' - not all first string. But I'm tell length os string with "\027" in start of string. Where I'm mistaken?
Edit 1:
I've changed code to:
if (Reg == 0) {xResult.val.str = L"\035Ошибка диапазона параметров";debugPrintf("Reg = 0");}
if (Reg == 1) {xResult.val.str = L"\012Вода";debugPrintf("Reg = 1");}
if (Reg == 2) {xResult.val.str = L"\022Перегретый пар";debugPrintf("Reg = 2");}
if (Reg == 3) {xResult.val.str = L"\025Критическая смесь";debugPrintf("Reg = 3");}
if (Reg == 4) {xResult.val.str = L"\022Насыщенный пар";debugPrintf("Reg = 4");}
if (Reg == 5) {xResult.val.str = L"\027Сверхперегретый пар";debugPrintf("Reg = 5");}
But I've got this:
What do you think about?
Edit 2: My function signature type:
{
L"PTstate", // Function name/ordinal
L"UBB", // Func signature type
L"PTstate", // Func name in Func wizard
L"P, T", // Arg name in Func wizard
L"1", // Function type
L"SimpleXll2007", // Category in Func wizard
L"", // Shortcut (commands only)
L"", // Help topic
L"", // Func help in Func wizard
L"", // Arg help in Func wizard
L"" // Arg help in Func wizard
}
I've used char* for returning string. Who find solution with XLOPER12 - welcome!