• <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>
            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類的實現(xiàn)

            #ifndef DLL_FILE

            #define DLL_FILE

            #endif

            #include "point.h"

            //類point的缺省構(gòu)造函數(shù)

            point::point()

            {

            x = 0.0;

            y = 0.0;

            }

            //類point的構(gòu)造函數(shù)

            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類的實現(xiàn)

            #ifndef DLL_FILE

            #define DLL_FILE

            #endif

            #include "circle.h"

            #define PI 3.1415926

            //circle類的構(gòu)造函數(shù)

            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的類實現(xiàn)代碼中定義了宏DLL_FILE,故在DLL的實現(xiàn)中所包含的類聲明實際上為:

            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 2005-11-25 18:26 艾凡赫 閱讀(11350) 評論(0)  編輯 收藏 引用 所屬分類: DLL 技術
            波多野结衣AV无码久久一区| 久久婷婷人人澡人人| 色青青草原桃花久久综合| 亚洲人成网站999久久久综合 | A级毛片无码久久精品免费| 日产精品久久久一区二区| 色综合久久中文综合网| 久久五月精品中文字幕| 久久人人爽人人爽人人片AV麻烦| 久久久久国产精品| 一个色综合久久| 亚洲午夜精品久久久久久人妖| AV无码久久久久不卡蜜桃| 日本精品久久久中文字幕| 精品综合久久久久久97| 99久久国产综合精品五月天喷水| 国产毛片欧美毛片久久久| 久久久久国产亚洲AV麻豆| 国内精品久久久久久久久电影网| 久久九九亚洲精品| 亚洲色欲久久久综合网东京热| 精品久久久久中文字| 国产精品久久久久…| 久久综合给合久久国产免费 | 热久久这里只有精品| 久久久久亚洲AV片无码下载蜜桃| 久久久久国产| 国产激情久久久久影院小草| 国产激情久久久久影院老熟女| 久久精品99久久香蕉国产色戒 | 久久水蜜桃亚洲av无码精品麻豆| 少妇久久久久久被弄到高潮| 中文字幕无码久久久| 久久婷婷五月综合成人D啪| 香港aa三级久久三级| 国产精品久久久久9999| www性久久久com| 久久亚洲高清综合| 久久青青草原精品国产软件| 久久精品国产99国产精品| 精品久久久久中文字|