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

            醬壇子

            專注C++技術 在這里寫下自己的學習心得 感悟 和大家討論 共同進步(歡迎批評!!!)

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              66 Posts :: 16 Stories :: 236 Comments :: 0 Trackbacks

            公告

            王一偉 湖南商學院畢業 電子信息工程專業

            常用鏈接

            留言簿(19)

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 387109
            • 排名 - 64

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            DLL導出類(轉)

              DLL中定義的類可以在應用工程中使用。

              下面的例子里,我們在DLL中定義了point和circle兩個類,并在應用工程中引用了它們(單擊此處下載本工程附件)。

            //文件名:point.h,point類的聲明

            #ifndef POINT_H

            #define POINT_H

            #ifdef DLL_FILE

            class _declspec(dllexport) point //導出類point

            #else

            class _declspec(dllimport) point //導入類point

            #endif

            {

            public:

            float y;

            float x;

            point();

            point(float x_coordinate, float y_coordinate);

            };

            #endif


            //文件名:point.cpp,point類的實現

            #ifndef DLL_FILE

            #define DLL_FILE

            #endif

            #include "point.h"

            //類point的缺省構造函數

            point::point()

            {

            x = 0.0;

            y = 0.0;

            }

            //類point的構造函數

            point::point(float x_coordinate, float y_coordinate)

            {

            x = x_coordinate;

            y = y_coordinate;

            }


            //文件名:circle.h,circle類的聲明

            #ifndef CIRCLE_H

            #define CIRCLE_H

            #include "point.h"

            #ifdef DLL_FILE

            class _declspec(dllexport)circle //導出類circle

            #else

            class _declspec(dllimport)circle //導入類circle

            #endif

            {

            public:

            void SetCentre(const point ¢rePoint);

            void SetRadius(float r);

            float GetGirth();

            float GetArea();

            circle();

            private:

            float radius;

            point centre;

            };

            #endif


            //文件名:circle.cpp,circle類的實現

            #ifndef DLL_FILE

            #define DLL_FILE

            #endif

            #include "circle.h"

            #define PI 3.1415926

            //circle類的構造函數

            circle::circle()

            {

            centre = point(0, 0);

            radius = 0;

            }

            //得到圓的面積

            float circle::GetArea()

            {

            return PI *radius * radius;

            }

            //得到圓的周長

            float circle::GetGirth()

            {

            return 2 *PI * radius;

            }

            //設置圓心坐標

            void circle::SetCentre(const point ¢rePoint)

            {

            centre = centrePoint;

            }

            //設置圓的半徑

            void circle::SetRadius(float r)

            {

            radius = r;

            }

            類的引用:

            #include "..\circle.h"  //包含類聲明頭文件

            #pragma comment(lib,"dllTest.lib");


            int main(int argc, char *argv[])

            {

            circle c;

            point p(2.0, 2.0);

            c.SetCentre(p);

            c.SetRadius(1.0);

            printf("area:%f girth:%f", c.GetArea(), c.GetGirth());


            return 0;

            }


              從上述源代碼可以看出,由于在DLL的類實現代碼中定義了宏DLL_FILE,故在DLL的實現中所包含的類聲明實際上為:

            class _declspec(dllexport) point //導出類point

            {



            }


              和

            class _declspec(dllexport) circle //導出類circle

            {



            }


              而在應用工程中沒有定義DLL_FILE,故其包含point.h和circle.h后引入的類聲明為:

            class _declspec(dllimport) point //導入類point

            {



            }


              和

            class _declspec(dllimport) circle //導入類circle

            {



            }


            posted on 2006-12-13 12:13 @王一偉 閱讀(5647) 評論(3)  編輯 收藏 引用

            Feedback

            # re: DLL導出類 2007-03-26 15:58 馮博
            問大俠,如果類中含有友元怎么做?我的總是出錯~~
            我是這么寫的:
            #ifdef DLL_FILE
            _declspec(dllexport) friend std::ostream& operator<<(std::ostream& os,Circle& c)
            #else
            _declspec(dllimport) friend std::ostream& operator<<
            (std::ostream& os,Circle& c)
            #endif
            {
            os<<"some thing";
            return os;
            }

            每次主文件里cout << circle的時候就當掉了~~
            my email:vonboo@163.com  回復  更多評論
              

            # re: DLL導出類 2007-08-11 11:14 filebat
            可不可以在沒有lib只有dll的情況下,使用dll中的類?  回復  更多評論
              

            # re: DLL導出類 2007-08-11 13:15 SmartPtr
            @filebat
            兩個好問題, 期待樓主解答  回復  更多評論
              

            久久久久99精品成人片欧美| 一级做a爰片久久毛片看看| 久久精品www人人爽人人| 国产精品毛片久久久久久久| 国产农村妇女毛片精品久久| 久久久久久免费视频| 亚洲AV无码久久精品狠狠爱浪潮 | 日韩久久久久久中文人妻| 久久亚洲精品国产精品| 久久精品?ⅴ无码中文字幕| 国产69精品久久久久观看软件| 成人久久久观看免费毛片| 午夜视频久久久久一区| 色综合久久综精品| 伊人久久大香线蕉av一区| 精品久久综合1区2区3区激情| 77777亚洲午夜久久多喷| 国产成人精品久久| 久久精品国产亚洲AV无码偷窥| 欧美日韩成人精品久久久免费看| 久久99毛片免费观看不卡| 99久久香蕉国产线看观香 | 国产69精品久久久久9999APGF| 99久久精品免费国产大片| 国产成人精品白浆久久69| 欧美亚洲国产精品久久| 久久精品国产精品亚洲下载| 久久99热国产这有精品| 99久久99久久| 99久久无色码中文字幕| 91精品国产91久久综合| 东方aⅴ免费观看久久av| 国产精品久久久久免费a∨| 日本亚洲色大成网站WWW久久| 久久久久久一区国产精品| 久久99久久无码毛片一区二区| 日韩亚洲欧美久久久www综合网| 久久精品国产91久久麻豆自制| 精品久久久久久久| 香蕉久久一区二区不卡无毒影院| 狠狠狠色丁香婷婷综合久久俺|