dll的建立及使用(源碼)

來源:互聯網
上載者:User

本文出自:http://blog.csdn.net/closeall2008 

dll的建立:

下面用代碼執行個體簡單的介紹一下如何建立dll以及如何使用dll。

       1、首先建立一個dll的標頭檔。dll的源碼檔案(.cpp)需要包含這個標頭檔,而且使用這個動態串連庫的可執行檔也需要這個標頭檔。這個標頭檔包含你想要從dll輸出的函數的原型、結構和符號。下面是一個名為dll.h檔案的的例子。

 //dll.h
//author: clsoeall
//time : 2005.09
////////////////////////////////////////////////////////////////////
#ifndef DLL_H_
#define DLL_H_

#define MYFIRSTDLL extern "C" __declspec( dllexport )

MYFIRSTDLL void ShowText() ;

#endif

      2、然後建立dll.cpp.代碼如下。

//dll.cpp
//author: closeall
//time : 2005.09
///////////////////////////////////////////////////////////////////
//#define MYFIRSTDLL extern "C" __declspec( dllexport )

#include <stdio.h>
#include "dll.h"

void ShowText()
{
 printf( "This is dll export show  /n" ) ;
}

編譯完成以後,就會產生一個dll.dll的檔案和一個dll.lib 的檔案。在使用dll.dll這個動態串連庫的時候,應該把dll.h標頭檔包含在可執行檔中,而且還要把dll.lib連入程式。

下面的代碼是使用這個動態串連庫的測試程式。

//testdll.cpp
//author: closeall
//time : 2005.09
///////////////////////////////////////////////
#include <stdio.h>
#include <iostream.h>
#include "dll.h"
#pragma comment( lib, "dll.lib" )

int main()
{
 ShowText() ; //這個函數是從動態串連庫dll.dll中調用的
 printf( "This is execute show /n" ) ;

 int i ;
 cin>> i ;
 return 1 ;
}

(完)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.