• <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類的實現

            #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 2005-11-25 18:26 艾凡赫 閱讀(11350) 評論(0)  編輯 收藏 引用 所屬分類: DLL 技術
            久久久亚洲欧洲日产国码是AV | 久久亚洲精品成人无码网站| 久久久一本精品99久久精品66| 狠狠精品干练久久久无码中文字幕| 9久久9久久精品| 久久久久久久亚洲精品| 欧美日韩精品久久久久| 2021少妇久久久久久久久久| 热99RE久久精品这里都是精品免费 | 久久夜色精品国产网站| 久久精品国产亚洲Aⅴ蜜臀色欲| 国产亚洲精品久久久久秋霞| 国产精品伊人久久伊人电影| 狠狠色综合网站久久久久久久高清 | 久久久精品久久久久特色影视| 久久综合精品国产二区无码| 2020久久精品国产免费| 久久天天躁狠狠躁夜夜avapp| 久久久久久久亚洲精品| 亚洲欧洲精品成人久久曰影片| 久久国产色AV免费看| 久久人人爽人人爽人人片av高请| 国产激情久久久久影院小草| 人妻无码久久精品| 亚洲国产精品无码久久| 无码八A片人妻少妇久久| 国产午夜精品久久久久免费视 | 久久精品国产亚洲AV无码麻豆| 精品久久久噜噜噜久久久| 久久无码国产| 九九久久精品无码专区| 91精品国产高清久久久久久国产嫩草 | 久久亚洲精精品中文字幕| 久久久国产精品网站| 久久久久亚洲AV成人网人人网站 | 久久精品嫩草影院| 久久91亚洲人成电影网站| 99久久综合狠狠综合久久| 91精品国产高清久久久久久国产嫩草| 久久国产高清字幕中文| 久久精品国产精品亚洲人人 |