• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            春暖花開
            雪化了,花開了,春天來了
            posts - 149,comments - 125,trackbacks - 0
            今天在做東西的時候,用LoadString遇到了一些問題.可能大家日后也會用到,分享一下.

            LoadString 從資源載入字符串,我們一般這么用。
            舉個例子:
            TCHAR str[20];
            LoadString(hInstance, IDS_STR, str, 20);

            如果我們的字符串的長度不知道,或許它會變化的話,我們怎么來獲得資源ID對應的字符串呢?這就要用到
            LoadString的另一種用法,我們可以這樣用
            LPCTSTR lpcStr = (LPCTSTR)LoadString(hInstance, IDS_STR, NULL, 0);

            感覺上沒有什么問題?。?br>
            但是實際應用中又出現問題了,讀出的字符串沒有截斷處理,它包含了下一個ID包含的字符串或者更多。

            怎么辦?在MSDN中,LoadString已經清楚地指出
            lpBuffer is set to NULL, the return value is a pointer to the requested string. The caller should cast the return value to an LPCTSTR. This pointer points directly to the resource, so the string is read-only. The length of the string, not including any terminating null character, can be found in the word preceding the string.

            同時它也給出了解決辦法:
            To use the lpBuffer pointer, the n flag must be set with the resource compiler, RC.
            Note   String resources are not null-terminated by default. When lpBuffer is set to NULL, verify whether the string resource represented by the pointer returned by LoadString is null-terminated, and if necessary, append a terminating null character to the resource before using it in your application.

            一開始我沒有太明白the n flag must be set with the resource compiler, RC.的含義,很迷惑,不知道如何解決。但是在網上尋找方法的時候,發現這么一篇文章
            http://lak4cyut.blogspot.com/2008/08/wm-api-loadstring.htmlWM API : LoadString() 另一種使用方式),我才徹底明白過來。

            我使用的是VS2005,在project->properties->Resource->Command Line中添加一個 “-n”,即可。

            在運行程序,正常顯示了。

            大家如遇相同問題,可以試試這個方法。
            posted on 2008-12-17 20:07 Sandy 閱讀(6642) 評論(8)  編輯 收藏 引用 所屬分類: windows學習

            FeedBack:
            # re: LoadString的一些小用法
            2008-12-17 23:24 | 萬連文
            看看VC的CString的LoadString的方法,可以自己封裝一個Win32版本的,你這個方法不是那么徹底解決問題。  回復  更多評論
              
            # re: LoadString的一些小用法
            2008-12-18 08:28 | Sandy
            @萬連文
            這個我還真的沒有想到.謝謝提醒.我自己也封裝了一個,可是用起來比較麻煩,我去看看CString的LoadString怎么實現的.  回復  更多評論
              
            # re: LoadString的一些小用法
            2008-12-18 22:30 | dell筆記本
            不錯,好東西  回復  更多評論
              
            # re: LoadString的一些小用法
            2010-06-05 23:31 | VickieCastaneda
            Don't you know that it is high time to receive the <a href="http://lowest-rate-loans.com/topics/home-loans">home loans</a>, which would make you dreams real.   回復  更多評論
              
            # re: LoadString的一些小用法
            2010-06-15 09:32 | thesis
            Thank you a lot for your supreme issue referring to this good post. I could not find this kind of thesis report in web and wanted to buy the dissertation. Thus, I have all needed stuff at this time.   回復  更多評論
              
            # re: LoadString的一些小用法
            2010-08-02 09:25 | Freelance writing job
            I come to writing jobs service, with the aim to information close to this topic.   回復  更多評論
              
            # re: LoadString的一些小用法
            2010-08-05 05:26 | ringtones
            Some people will dispute much about your superior thought. I opine that, the great get ringtones service has to consult with you to produce the perfect quality free downloadable ringtones blog issue.   回復  更多評論
              
            # re: LoadString的一些小用法
            2010-10-07 11:25 | resume writing
            Are you willing to get resume, which suit the range of study you expect?. You can count on our resume writers, as you rely on yourself. Thanks because it’s the interesting  回復  更多評論
              
            亚洲欧美日韩精品久久| 91精品国产综合久久精品| 日产久久强奸免费的看| 欧美性大战久久久久久| 色欲久久久天天天综合网精品| 国内精品久久久久影院一蜜桃| 久久久国产精华液| 精品久久人人爽天天玩人人妻| 久久精品国产91久久麻豆自制| 久久伊人五月天论坛| 国产成年无码久久久久毛片| 亚洲а∨天堂久久精品| AAA级久久久精品无码片| 模特私拍国产精品久久| 久久精品国产一区| 久久综合亚洲欧美成人| 久久99九九国产免费看小说| 国产日韩欧美久久| 精品久久久无码人妻中文字幕豆芽| 欧美成a人片免费看久久| 久久精品免费观看| 久久婷婷五月综合97色一本一本 | 欧美久久一区二区三区| 久久精品国产99久久无毒不卡| 亚洲国产精品成人AV无码久久综合影院 | 人妻无码久久一区二区三区免费| 精品国产婷婷久久久| 久久人人爽爽爽人久久久| 久久亚洲精品国产亚洲老地址| 99久久精品国产一区二区蜜芽| 大伊人青草狠狠久久| 亚洲国产精品18久久久久久| 久久精品成人欧美大片| 一级女性全黄久久生活片免费 | 夜夜亚洲天天久久| 久久综合丝袜日本网| 亚洲综合婷婷久久| 久久精品国产亚洲Aⅴ香蕉| 国内精品久久久久久久久| 久久www免费人成精品香蕉| 精品国产综合区久久久久久|