'Does LoadString allocate memory for the string it writes to?

I am new in c++ and need some help. I created a resource-only dll that contains strings, i need to use this dll in a different project to read the stored strings.

I wrote the following functions to read the read the strings:

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;
}

What should i change in my code to get the expected output - stringggg? Why is it happening? Did LoadString allocate memory for the string it read from resources, or i just got pointer to the place in memory the string is already stored? Thanks for your help!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source