私は c++ が初めてで、助けが必要です。文字列を含むリソースのみの dll を作成しました。この dll を別のプロジェクトで使用して、保存されている文字列を読み取る必要があります。
文字列を読み取るために次の関数を作成しました。
LPTSTR GetResourceStr(HMODULE resContainer,int resourceID)
{
//The stings that are stored in the dll are:
//
//ID |Value|Caption
//__________________________________________
//IDS_STRING101 |101 |stringggg
//IDS_STRING102 |102 |string 102
//IDS_STRING103 |103 |string 103
LPTSTR strBuffer = NULL;//is a (non-const) TCHAR string
if(0!=resContainer){
int copied=LoadString(resContainer,resourceID ,(LPTSTR)&strBuffer,0);
}
return strBuffer;
}
int _tmain(int argc, _TCHAR* argv[])
{
HMODULE resContainer=LoadLibraryEx(L"ResourceDll.dll",NULL, LOAD_LIBRARY_AS_DATAFILE);
LPTSTR msg = GetResourceStr(resContainer,101);
std::wcout<<msg<<std::endl;
//Expected output: stringggg
//The output that i get: stringgggstring 102 string 103
int i = 0;
std::cin>>i;
return 0;
}
期待される出力 - stringgggを取得するには、コードで何を変更する必要がありますか? なぜそれが起こっているのですか? LoadString はリソースから読み取った文字列にメモリを割り当てましたか、それとも文字列が既に格納されているメモリ内の場所へのポインタを取得しましたか? ご協力いただきありがとうございます!!