diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 80323fe1366..92288fcd88d 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -1749,10 +1749,27 @@ static HRESULT Global_Asc(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VA str = conv_str; } - if(!SysStringLen(str) || *str >= 0x100) + if(!SysStringLen(str)) hres = MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL); - else if(res) - hres = return_short(res, *str); + else { + unsigned char buf[2]; + short val = 0; + int n = WideCharToMultiByte(CP_ACP, 0, str, 1, (char*)buf, sizeof(buf), NULL, NULL); + switch(n) { + case 1: + val = buf[0]; + break; + case 2: + val = (buf[0] << 8) | buf[1]; + break; + default: + WARN("Failed to convert %x\n", *str); + hres = MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL); + } + if(SUCCEEDED(hres)) + hres = return_short(res, val); + } + SysFreeString(conv_str); return hres; } diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index be95aae4b91..48b263334c8 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -1842,6 +1842,11 @@ call testAsc(" ", 32) call testAsc(Chr(255), 255) call testAsc(Chr(0), 0) if isEnglishLang then testAsc true, 84 +if Asc(Chr(&h81)) = &h8145 then + ' Japanese (CP 932) + call testAsc(Chr(&h8e8e), -29042) + call testAsc(Chr(220), 220) +end if call testAscError() sub testErrNumber(n)