weird result from excel range

May 10, 2012 at 10:57 AM

Greetings,

first of all, thanks a lot for this library it helped me a lot.

I am trying to get excel range of strings, perform some operation on them and return the range back to excel,

static AddInX xai_function2(
	FunctionX(XLL_LPOPERX, _T("?xll_function2"), _T("compare2"))
	.Arg(XLL_LPOPERX, _T("Str"), _T("is a char* NULL terminated C style string."))
	.Category(CATEGORY)
	.FunctionHelp(_T("Description of what function does."))
	.Documentation(_T("Optional documentation for function."))
);
LPOPERX WINAPI xll_function2(const LPOPERX cell)
{
#pragma XLLEXPORT
	static OPERX xResult, res;
	xResult = *(cell);
	assert(xResult.xltype== xltypeMulti);
	XCHAR* str = cell[0].val.str;
	...
	return &res;
} 

when I tried to see what is in str variable, it always give me weird result, like 

 str = "﷽yonas﷽﷽娯㒒", it should have been just "yonas"!!. please help me...

 

/bs

Coordinator
May 10, 2012 at 11:10 AM

Excel strings are counted strings. The first character is the length of the string and the string is not null terminated.

May 10, 2012 at 11:40 AM
keithalewis wrote:

Excel strings are counted strings. The first character is the length of the string and the string is not null terminated.

but how do I convert counted string to string, I mean I could do that if I know the length of the string but its not possible because the first character is not even a string.

"﷽yonas﷽﷽娯㒒",

is there any way to convert the first character to integer?

Coordinator
May 10, 2012 at 12:04 PM

OPERX o(_T("is lazy"));
ensure (o.xltype == xltypeStr);
std::string yonas(o.val.str + 1, o.val.str[0]);
ensure (yonas == _T("is lazy"));

May 10, 2012 at 12:26 PM
Edited May 10, 2012 at 12:37 PM
keithalewis wrote:

OPERX o(_T("is lazy"));
ensure (o.xltype == xltypeStr);
std::string yonas(o.val.str + 1, o.val.str[0]);
ensure (yonas == _T("is lazy"));

thanks a lot, I actually got the size of the string as unsigned int size = yonas[0] and transfer the content to another string and worked pretty well,

 yonas isn't lazy though ;)

Coordinator
Jul 4, 2012 at 12:33 PM

I work very hard to be lazy.