変更)
LPWSTR CreateUnicode(LPWSTR Unicode, COMDATA* data, int temporary)
{
if (!Unicode) return 0;
//Copy Unicode
int BuffLen=wcslen(Unicode)+1;
LPWSTR Unicode2=(LPWSTR)((int)data->Malloc(BuffLen*2,temporary));
wcscpy_s(Unicode2,BuffLen,Unicode);
return Unicode2;
}
変更)
char* CreateAnsiString(LPSTR ANSI, COMDATA* data, int temporary)
{
if (!ANSI) return 0;
//Copy ANSI
int StrLen=strlen(ANSI)+1;
char* str=(char*)data->Malloc(StrLen,temporary);
strcpy_s(str,StrLen,ANSI);
return str;
}
削除)
LPWSTR CreateFixedLengthUnicode(LPSTR ANSI,COMDATA* data, int length, int temporary)
LPWSTR CreateFixedLengthUnicode(LPWSTR Unicode,COMDATA* data, int length, int temporary)
LPWSTR CreateUnicode(LPSTR ANSI,COMDATA* data, int temporary)
var API = new ActiveXObject('SfcMini.DynaCall');
API.LoadLibrariesW('kernel32', 'user32');
var buf = new ActiveXObject('SfcMini.Structure');
buf('value', 'Unicode*1000');
var len = API.GetPrivateProfileSection('boot loader', buf, 1000, 'C:\\boot.ini');
API.MessageBox(0, buf.value.substr(0, len).replace(/\u0000/g, '\n'), 'test', 0);
common.cpp
追加) BSTR ConvertANSItoBSTR(LPSTR mbs, int mbs_len) { int wcs_len = MultiByteToWideChar(CP_ACP, 0, mbs, mbs_len, NULL, 0); wchar_t *wcs = new wchar_twcs_len; MultiByteToWideChar(CP_ACP, 0, mbs, mbs_len, wcs, wcs_len); BSTR bstr; bstr = SysAllocStringLen(wcs, wcs_len); delete wcs; return bstr; }
変更) LPWSTR CreateUnicode(LPWSTR Unicode, COMDATA* data, int temporary) { if (!Unicode) return 0; //Copy Unicode int BuffLen=wcslen(Unicode)+1; LPWSTR Unicode2=(LPWSTR)((int)data->Malloc(BuffLen*2,temporary)); wcscpy_s(Unicode2,BuffLen,Unicode); return Unicode2; }
変更) char* CreateAnsiString(LPSTR ANSI, COMDATA* data, int temporary) { if (!ANSI) return 0; //Copy ANSI int StrLen=strlen(ANSI)+1; char* str=(char*)data->Malloc(StrLen,temporary); strcpy_s(str,StrLen,ANSI); return str; }
削除) LPWSTR CreateFixedLengthUnicode(LPSTR ANSI,COMDATA* data, int length, int temporary) LPWSTR CreateFixedLengthUnicode(LPWSTR Unicode,COMDATA* data, int length, int temporary) LPWSTR CreateUnicode(LPSTR ANSI,COMDATA* data, int temporary)
structure.cpp
L162 前) pVarResult->bstrVal=SysAllocString(CreateUnicode((LPSTR)*pInt,data,MALLOC_TEMPORARY));//copy as Unicode for export 後) pVarResult->bstrVal=MultiByteToBSTR(ANSI,-1);//copy as Unicode for export L168 前) pVarResult->bstrVal=SysAllocString(CreateUnicode((LPWSTR)*pInt,data,MALLOC_TEMPORARY));//copy Unicode for export 後) pVarResult->bstrVal=SysAllocString((LPWSTR)*pInt);//copy Unicode for export L176 前) pVarResult->bstrVal=SysAllocString(CreateFixedLengthUnicode(ANSI,data,i,MALLOC_TEMPORARY)); 後) pVarResult->bstrVal=MultiByteToBSTR(ANSI,i); L182 前) pVarResult->bstrVal=SysAllocString(CreateFixedLengthUnicode(Unicode,data,i,MALLOC_TEMPORARY)); 後) pVarResult->bstrVal=SysAllocStringLen(Unicode,i); tools.cpp
L82 前) pVarResult->bstrVal=SysAllocString(CreateUnicode(ANSI2,data,MALLOC_TEMPORARY)); 後) pVarResult->bstrVal=ConvertANSItoBSTR(ANSI2,-1); NULL 文字を含む文字列の動作確認は以下のスクリプトで行いました。
var API = new ActiveXObject('SfcMini.DynaCall'); API.LoadLibrariesW('kernel32', 'user32'); var buf = new ActiveXObject('SfcMini.Structure'); buf('value', 'Unicode*1000'); var len = API.GetPrivateProfileSection('boot loader', buf, 1000, 'C:\\boot.ini'); API.MessageBox(0, buf.value.substr(0, len).replace(/\u0000/g, '\n'), 'test', 0);