• <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>

            concentrate on c/c++ related technology

            plan,refactor,daily-build, self-discipline,

              C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              37 Posts :: 1 Stories :: 12 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(9)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            1) 使用windows 頭文件
            API 頭文件允許32位和64位應(yīng)用程序,包含了ANSI版本和UNICODE版本的聲明。
            如果安裝更新SDK的話,那么就可能有頭文件的多個(gè)版本在機(jī)器上面。
            一些函數(shù)的使用可能會(huì)通過(guò)使用條件編譯代碼依賴(lài)于某個(gè)特定版本的操作系統(tǒng),為了編譯成功,你得定義比較合適的macro.頭文件使用宏來(lái)指示哪個(gè)版本系統(tǒng)支持編程元素。
            http://msdn2.microsoft.com/en-us/library/aa383745(VS.85).aspx
            2) 初始化類(lèi)中的成員模板
            i) 使用非模板的方式
            template <typename Argtype>
            class Option
            {
            public:
            Option( void (*func_name)(Argtype), Argtype Arg1 )
              : MenuFunction<Argtype>( (*func_name)(Argtype), Argtype Arg1 )
             {
             } 
            private:
             MenuFunction<Argtype> function;
            };
            template <typename Argtype>
            Option<Argtype> makeOption(void (*func_name)(Argtype), Argtype Arg1 )
            {
            return Option<Argtype>(func_name, Arg1);
            }

            ii) 使用多態(tài)
            class Option
            {
            private:
            class FunctionBase
            {
            public:
            virtual ~FunctionBase() {}
            virtual void call() = 0;
            };

            template <typename Argtype>
            class Function : public FunctionBase
            {
            public:
            Function(void (*func_name)(Argtype), Argtype arg) :
            m_func(func_name, arg)
            {
            }
            void call()
            {
            m_func(); // or whatever
            }
            private:
            MenuFunction<Argtype> m_func;
            };

            public:
            template<typename Argtype> Option( void (*func_name)(Argtype), Argtype Arg1 )
            {
             // of course, this means you need a destructor, copy constructor, and assignment operator
            // function->call() would invoke the function
            function = new Function<Argtype>(func_name, Arg1);

            }  
            FunctionBase * function;
            };
            3 大小寫(xiě)字符串比較大小(考慮區(qū)域性語(yǔ)言的問(wèn)題)
            #include <iostream>
            #include<algorithm>
            #include<functional>
            #include<boost/bind.hpp>
            #include<string>
            #include<locale>

            struct CaseSensitiveString
            {
              public:
                   bool operator()(const std::string & lhs,const std::string & rhs)
                   {
                          std::string lhs_lower;
                          std::string rhs_lower;
                          std::transform(lhs.begin(),lhs.end(),std::back_inserter(lhs_lower),bind(std::tolower<char>,_1,_loc));
                          std::transform(rhs.begin(),rhs.end(),std::back_inserter(rhs_lower),bind(std::tolower<char>,_1,_loc));
                          return lhs_lower < rhs_lower;
                   }
                  CaseSensitiveString(const std::locale & loc):_loc(loc){}
                 private:
                   std::locale _loc;
            };
            詳細(xì)內(nèi)容見(jiàn):
            http://learningcppisfun.blogspot.com/2008/04/case-insensitive-string-comparison.html

            4 找不到msctf.h問(wèn)題
            在用DX自帶的dxut做界面程序的時(shí)候,整個(gè)程序編制下來(lái)就出現(xiàn)了這個(gè)錯(cuò)誤
            fatal error C1083: Cannot open include file: 'msctf.h': No such file or directory
            很詭異的,在dxsdk里面也找不到,想了很久,才發(fā)現(xiàn)自己沒(méi)有安裝platform sdk.因?yàn)閣in32程序之類(lèi)的,最好都要安裝這些sdk之類(lèi)的。具體的信息可以在這里得到
            http://www.gamedev.net/community/forums/topic.asp?topic_id=481358
            5 重載 , 覆蓋,隱藏
            重載與覆蓋有以下的區(qū)別:
            重載:同一類(lèi),相同函數(shù)名,不同函數(shù)參數(shù),不一定要有virtual 關(guān)鍵字
            覆蓋:子類(lèi)和父類(lèi),相同函數(shù)名,  相同函數(shù)參數(shù),一定要有virtual 關(guān)鍵字
            隱藏:1)如果派生類(lèi)的函數(shù)名與基類(lèi)的函數(shù)名相同,但是參數(shù)不同,不論有無(wú)virtual關(guān)鍵字,基類(lèi)的函數(shù)將被隱藏(與重載區(qū)別開(kāi)來(lái))
                        2)如果派生類(lèi)的函數(shù)名與基類(lèi)的函數(shù)名相同,并且參數(shù)相同,但是基類(lèi)沒(méi)有virtual關(guān)鍵字,基類(lèi)的函數(shù)將被隱藏(與覆蓋區(qū)別開(kāi)來(lái))
            6 快速加載文件
            在游戲里面,一般對(duì)從硬盤(pán)或者DVD加載資源要求比較高的,一般采用這樣的方法:

            for(int i = 0; < NumBlocks; i++)
            {
               // VirtualAlloc() creates storage that is page aligned
               // and so is disk sector aligned
               blocks[i] = static_cast<char *>
                  (VirtualAlloc(0, BlockSize, MEM_COMMIT, PAGE_READWRITE));

               ZeroMemory(&overlapped[i], sizeof(OVERLAPPED));
               overlapped[i].hEvent = CreateEvent(0, false, false, 0);
            }

            HANDLE hFile = CreateFile(FileName, GENERIC_READ, 0, 0, OPEN_EXISTING,
               FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING |
               FILE_FLAG_OVERLAPPED | FILE_FLAG_SEQUENTIAL_SCAN, 0);

            int iWriterPos = 0;
            int iReaderPos = 0;
            int iIOPos = 0;
            int iPos = 0;

            do
            {
               while(iWriterPos - iReaderPos != NumBlocks && iIOPos < FileSize)
               {
                  overlapped[iWriterPos & NumBlocksMask].Offset = iIOPos;

                  int iLeft = FileSize - iIOPos;
                  int iBytesToRead = iLeft > BlockSize ? BlockSize: iLeft;

                  const int iMaskedWriterPos = iWriterPos & NumBlocksMask;
                  ReadFile(hFile, blocks[iMaskedWriterPos], iBytesToRead, 0,
                     &overlapped[iMaskedWriterPos]);

                  iWriterPos++;
                  iIOPos += iBytesToRead;
               }

               const int iMaskedReaderPos = iReaderPos & NumBlocksMask;

               WaitForSingleObject(overlapped[iMaskedReaderPos].hEvent, INFINITE);

               int iLeft = FileSize - iPos;
               int iBytesToRead = iLeft > BlockSize ? BlockSize: iLeft;

               memcpy(&g_buffer[iPos], blocks[iMaskedReaderPos], iBytesToRead);

               iReaderPos++;
               iPos += iBytesToRead;

            }
            while(iPos < FileSize);

            CloseHandle(hFile);

            for(int i = 0; i < NumBlocks; i++)
            {
               VirtualFree(blocks[i], BlockSize, MEM_COMMIT);
               CloseHandle(overlapped[i].hEvent);
            }

            char* s vs char s[]
            char s1[] = "abcd";// 定義一個(gè)未指定長(zhǎng)度的char型數(shù)組,并使用字符串"abcd"將之初始化
            char *s2  = "abcd";// 定義一個(gè)char型指針,并將其指向字符串"abcd",該字串位于靜態(tài)存儲(chǔ)區(qū)

            s1[0] = 'm';// 無(wú)編譯期、運(yùn)行期錯(cuò)誤
            s2[0] = 'm';// 無(wú)編譯器錯(cuò)誤,但運(yùn)行期試圖修改靜態(tài)內(nèi)存,所以發(fā)生運(yùn)行期錯(cuò)誤
            char s*只是被賦予了一個(gè)指針,char s[]是在棧中重新開(kāi)辟了空間,可以在程序中寫(xiě),而不引起程序崩潰。
            所以相比較而言,使用字符串?dāng)?shù)組要比字符指針要安全的多,要慎用char*s 和char s[].
            7 can not find MSVCR80.dll
            在安裝了vc2005之后,發(fā)現(xiàn)錯(cuò)誤報(bào)告說(shuō)MSVCR80.dll,以為又要重新安裝vc2005了,但是在網(wǎng)絡(luò)上面搜索到另外一個(gè)例子說(shuō),其實(shí)可以不用安裝vc2005,直接改變配置就好了,于是就有這個(gè)了:
            http://blogs.msdn.com/seshadripv/archive/2005/10/30/486985.aspx
            http://www.codeguru.com/forum/showthread.php?t=439964
            工程架構(gòu):
            新建一個(gè)空白的 solution.
            然后在新建的solution上面添加vcproject.
            并且也可以在子空白solution上面添加vcproject.

            1>        ]
            1>正在編譯資源...
            1>正在鏈接...
            1>LINK : warning LNK4075: 忽略“/INCREMENTAL”(由于“/OPT:ICF”規(guī)范)
            1>fatal error C1900: Il mismatch between 'P1' version '20060201' and 'P2' version '20050411'
            1>LINK : fatal error LNK1257: 代碼生成失敗
            1>生成日志保存在“file://e:\demo-work\LocalVersionTianJi\_out\DragoonApp\Release\BuildLog.htm”
            1>DragoonApp - 1 個(gè)錯(cuò)誤,5382 個(gè)警告
            ========== 全部重新生成: 0 已成功, 1 已失敗, 0 已跳過(guò) ==========

            http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1512436&SiteID=1
            http://forum.codecall.net/c-c/6244-fatal-error-c1900-il-mismatch-between-p1-version-20060201-p2-version-2005-a.html
            http://www.codeguru.com/forum/archive/index.php/t-144030.html

            timeGetTime: 頭文件 mmsystem.h,庫(kù)文件 winmm.lib
            獲得當(dāng)前窗口的句柄。
            HWND hwnd=::GetForegroundWindow();
            hwnd就保存了當(dāng)前系統(tǒng)的最頂層窗口的句柄
            GetSafehWnd 取你程序所在窗口類(lèi)的句柄
            GetActiveWindow 取當(dāng)前活動(dòng)窗口句柄
            AfxGetMainWnd 取主窗口句柄
            GetForegroundWindow 取前臺(tái)窗口句柄
            FindWindow
            EnumWindow
            改變窗口屬性:
            SetWindowLong
            SetClassLong.

            strcpy strncpy memcpy.
            strcpy:按照msdn的話說(shuō)是:No overflow checking is performed when strings are copied or appended,即沒(méi)有嚴(yán)格的長(zhǎng)度檢查,所以即使是溢出也無(wú)法被檢查出來(lái),以及The behavior of strcpy is undefined if the source and destination strings overlap.

            strncpy:雖然加入了size這個(gè)來(lái)限制,但是這個(gè)size小于或者等于字符長(zhǎng)度的話,那么該信息是不被加上字符串結(jié)束符的.并且仍舊存在跟strcpy一樣的問(wèn)題, The behavior of strncpy is undefined if the source and destination strings overlap

            memcpy:具體的用法跟strncpy類(lèi)似,也加入了size的成分在里面,但是卻比strncpy好用得多.

            If the source and destination overlap, this function does not ensure that the original source characters in the overlapping region are copied before being overwritten.

            Use memmove to handle overlapping regions.

            顯然它能夠處理重疊的部分,安全可靠.
            并且:

            The first argument, dest, must be large enough to hold count characters of src; otherwise, a buffer overrun can occur.


            上次遇到的問(wèn)題是我將一串漢字用strcpy來(lái)拷貝到緩沖里面,結(jié)果發(fā)現(xiàn)出現(xiàn)了亂碼.
            strncpy, strcpy還是建議少用,換用memcpy+memmove(如果存在重疊的情況)吧:)
            未完待續(xù).

            posted on 2008-05-12 10:01 jolley 閱讀(2757) 評(píng)論(1)  編輯 收藏 引用

            Feedback

            # re: 大雜燴 2012-04-30 21:12 陳明澤
            請(qǐng)教:fatal error LNK1257: 代碼生成失敗如何解決呢?  回復(fù)  更多評(píng)論
              


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            东京热TOKYO综合久久精品| 青青热久久国产久精品 | 久久久久久久久波多野高潮| 91性高湖久久久久| 久久青青草原精品影院| 久久国产亚洲精品无码| 国产精品美女久久久久| 久久精品国产亚洲AV麻豆网站| 漂亮人妻被中出中文字幕久久 | 99久久综合国产精品免费| 久久性生大片免费观看性| 亚洲а∨天堂久久精品| 亚洲另类欧美综合久久图片区| 亚洲人成无码www久久久| 日韩精品久久久久久久电影| 久久国语露脸国产精品电影| 久久天堂AV综合合色蜜桃网| 成人国内精品久久久久影院| 91精品婷婷国产综合久久| 青草久久久国产线免观| 久久无码AV中文出轨人妻| 色狠狠久久AV五月综合| 久久免费高清视频| 一日本道伊人久久综合影| 色欲综合久久躁天天躁蜜桃| 欧美精品一区二区精品久久| 亚洲第一永久AV网站久久精品男人的天堂AV | 亚洲AV日韩AV永久无码久久 | 国产精品99精品久久免费| 一级做a爱片久久毛片| 污污内射久久一区二区欧美日韩| 久久精品中文字幕一区| 人人狠狠综合久久亚洲婷婷| 久久久精品久久久久影院| 久久国产亚洲精品麻豆| 无码八A片人妻少妇久久| 青青草原1769久久免费播放| 精品人妻伦九区久久AAA片69| 色综合色天天久久婷婷基地| 色偷偷88888欧美精品久久久| 国产精品亚洲综合专区片高清久久久|