• <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>
            春暖花開(kāi)
            雪化了,花開(kāi)了,春天來(lái)了
            posts - 149,comments - 125,trackbacks - 0
            今天在做東西的時(shí)候,用LoadString遇到了一些問(wèn)題.可能大家日后也會(huì)用到,分享一下.

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

            如果我們的字符串的長(zhǎng)度不知道,或許它會(huì)變化的話,我們?cè)趺磥?lái)獲得資源ID對(duì)應(yīng)的字符串呢?這就要用到
            LoadString的另一種用法,我們可以這樣用
            LPCTSTR lpcStr = (LPCTSTR)LoadString(hInstance, IDS_STR, NULL, 0);

            感覺(jué)上沒(méi)有什么問(wèn)題啊?

            但是實(shí)際應(yīng)用中又出現(xiàn)問(wèn)題了,讀出的字符串沒(méi)有截?cái)嗵幚恚讼乱粋€(gè)ID包含的字符串或者更多。

            怎么辦?在MSDN中,LoadString已經(jīng)清楚地指出
            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.

            同時(shí)它也給出了解決辦法:
            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.

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

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

            在運(yùn)行程序,正常顯示了。

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

            FeedBack:
            # re: LoadString的一些小用法
            2008-12-17 23:24 | 萬(wàn)連文
            看看VC的CString的LoadString的方法,可以自己封裝一個(gè)Win32版本的,你這個(gè)方法不是那么徹底解決問(wèn)題。  回復(fù)  更多評(píng)論
              
            # re: LoadString的一些小用法
            2008-12-18 08:28 | Sandy
            @萬(wàn)連文
            這個(gè)我還真的沒(méi)有想到.謝謝提醒.我自己也封裝了一個(gè),可是用起來(lái)比較麻煩,我去看看CString的LoadString怎么實(shí)現(xiàn)的.  回復(fù)  更多評(píng)論
              
            # re: LoadString的一些小用法
            2008-12-18 22:30 | dell筆記本
            不錯(cuò),好東西  回復(fù)  更多評(píng)論
              
            # 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.   回復(fù)  更多評(píng)論
              
            # 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.   回復(fù)  更多評(píng)論
              
            # 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.   回復(fù)  更多評(píng)論
              
            # 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.   回復(fù)  更多評(píng)論
              
            # 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  回復(fù)  更多評(píng)論
              
            久久亚洲中文字幕精品有坂深雪 | 精品久久综合1区2区3区激情| 久久久久久久久无码精品亚洲日韩 | 天天久久狠狠色综合| 国产ww久久久久久久久久| 久久国产成人亚洲精品影院| 国产精品久久久久久久久软件| 欧美大香线蕉线伊人久久| 精品国产福利久久久| 色综合合久久天天给综看| 色8久久人人97超碰香蕉987| 国产伊人久久| 91精品国产色综合久久| 亚洲精品第一综合99久久| 色综合久久久久| 久久超碰97人人做人人爱| 久久午夜免费视频| 国产精品激情综合久久| 麻豆AV一区二区三区久久| 内射无码专区久久亚洲| 久久―日本道色综合久久| 久久综合给合久久狠狠狠97色69 | 久久黄视频| 午夜欧美精品久久久久久久| 久久精品中文字幕第23页| 99久久er这里只有精品18| 久久久久久国产精品无码下载| 久久国产视屏| 久久精品国产一区二区电影| 色综合久久88色综合天天| 狠色狠色狠狠色综合久久| 精品久久久久久久无码| 三上悠亚久久精品| 久久亚洲精品无码AV红樱桃| 中文字幕无码精品亚洲资源网久久| 性高湖久久久久久久久AAAAA| 99久久精品国产综合一区 | 久久国产精品成人片免费| AV无码久久久久不卡蜜桃| 亚洲综合熟女久久久30p| 麻豆av久久av盛宴av|