+������ ������ str = SysAllocStringLen(NULL, 1023);Where this length comes from?
+������ ������ newstr = SysAllocStringLen(NULL, 1023);
Well, I tested String on windows xp, and found that 1023 was the limit, when given a number bigger than that, the output kept the length of 1023.
+������ ������ switch(V_VT(arg + 1)) {You only need first character, right? Then why do you need a full BSTR pointer in VT_BSTR case? And assigning it
+������ ������ case VT_NULL:
+������ ������ ������ ������ return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE);
+������ ������ case VT_BSTR:
+������ ������ ������ ������ str = V_BSTR(arg + 1);
+������ ������ ������ ������ break;
+������ ������ case������ VT_ARRAY|VT_BYREF|VT_VARIANT:
+������ ������ ������ ������ return DISP_E_TYPEMISMATCH;
+������ ������ default:
+������ ������ ������ ������ hres = to_short(arg + 1, &tmp);
+������ ������ ������ ������ if(FAILED(hres))
+������ ������ ������ ������ ������ ������ return hres;
+������ ������ ������ ������ str[0] = (char)tmp;
+������ ������ ������ ������ break;
+������ ������ }
to 'str' you leak a previously allocated buffer.
Why cast to (char)tmp?
+������ ������ else if(len == 0)Same way you're losing pointer to allocated buffer.
+������ ������ ������ ������ newstr = '\0';