Question

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:

enter image description here 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       
       }
Was it helpful?

Solution 2

I've used char* for returning string. Who find solution with XLOPER12 - welcome!

OTHER TIPS

When specifying the string length for the wide character string, the first wide character holds the length of the string. If it's purely cyrillic unicode this is 8 bytes, for just roman characters it'll be 4 bytes.

So this should work:

if (Reg == 0) {xResult.val.str = L"\035Ошибка диапазона параметров";debugPrintf("Reg = 0");}

See more here (see Table 2): http://msdn.microsoft.com/en-us/library/office/aa730920%28v=office.12%29.aspx

As far as I can see, the problem is the lengths of the strings you have specified are not in fact Octal.

I have taken your code and created a simplified example, with the correct Octal lengths and it works just fine.

__declspec(dllexport) LPXLOPER12 XLLMemoryE (int Reg)  // REGISTRATION Type UH
{ 

    static XLOPER12    xResult;

    xResult.xltype = xltypeStr;                 

    if (Reg == 0) {xResult.val.str = L"\034Ошибка диапазона параметров";}
    if (Reg == 1) {xResult.val.str = L"\004Вода";}
    if (Reg == 2) {xResult.val.str = L"\015Перегретый пар";}
    if (Reg == 3) {xResult.val.str = L"\021Критическая смесь";}
    if (Reg == 4) {xResult.val.str = L"\015Насыщенный пар";}
    if (Reg == 5) {xResult.val.str = L"\023Сверхперегретый пар";}

    return &xResult;        
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top