LoadString with nBufferMax equal 0

Kit*_*tet 4 c++ winapi

i am working on making my applications international. After two days digging on msdn i came up with a test, which loads language-specific library containing resources. This is also my first attempt at loading library as a resource, loading strings from it and so on.

Next, according to msdn example at http://msdn.microsoft.com/en-us/library/windows/desktop/dd319071%28v=VS.85%29.aspx, i'm trying the LoadString.

由于整个应用程序的字符串加载等于大量的文本复制,我想我会使用 LoadString 的 - 我认为是 - 内存高效功能,它将 nBufferMax 参数设置为零。根据 LoadString 文档,它应该返回一个指向字符串资源的指针。我想我会创建一个结构体或一类字符串指针,然后按照这些方式做一些事情(我只提取了重要的部分):

wchar_t textBuf[SOMEVALUE]; // <-- this is how id DOES work
wchar_t *myString; // <-- this is how i would like it
HMODULE resContainer=LoadLibraryEx(L"MUILibENU.dll",NULL, LOAD_LIBRARY_AS_DATAFILE);
if(0!=resContainer){
  // this works OK
  int copied=LoadStringW(resContainer,IDS_APP_TITLE,textBuf,SOMEVALUE); 
  // this fails, also gives a warning at compile time about uninitialized variable used.
  int copied=LoadStringW(resContainer,IDS_APP_TITLE,myString,0);
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我试图让 myString 成为指向加载的资源库字符串的指针,而无需实际复制任何内容。我的问题是:我误解了 msdn 文档吗?我可以还是不能直接在加载的库中获得指向字符串的指针,然后在以后简单地使用它,例如显示一个消息框,而不实际复制任何内容?直到我卸载所说的库?

ybu*_*ill 5

MSDN 说:

[...] 如果此参数为 0,则 lpBuffer 会收到一个指向资源本身的只读指针。

这意味着 a) 指针必须是类型const wchar_t*

const wchar_t *myString;
Run Code Online (Sandbox Code Playgroud)

b) 您必须传递一个指向该指针的指针并使用丑陋的强制转换:

int copied=LoadStringW(resContainer,IDS_APP_TITLE,(LPWSTR)&myString,0);
Run Code Online (Sandbox Code Playgroud)