生成dll文件,动态链接,静态链接

///
//
/***************************************************
 ***************************************************
  ShareInterface.h -- interface of dll library import and export
  version 1.0.8, Jan 27th, 2016

  Copyright (C) 2015-2016 Acheld CHEN

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

  Acheld CHEN       
  http://blog.csdn.net/acheld
  
 ***************************************************
 ****************************************************/
#pragma once

class ShareInterface
{
public:
	ShareInterface(void);
	~ShareInterface(void);
};

#ifdef _FX_EXPORT_INTERFACE
#define FX_SHAREAPI extern "C" __declspec(dllexport)
#else
#define FX_SHAREAPI extern "C" __declspec(dllimport)
#endif


FX_SHAREAPI void FXShareApiTest(DWORD_PTR dwPtr = NULL);
FX_SHAREAPI void FXShareApi(DWORD_PTR dwPtr = NULL);
//
//ShareInterface.dll
//
#include "StdAfx.h"
#include "ShareInterface.h"


ShareInterface::ShareInterface(void)
{
}


ShareInterface::~ShareInterface(void)
{
}

FX_SHAREAPI void FXShareApiTest( DWORD_PTR dwPtr /*= NULL*/ )
{
	MessageBox(NULL,(LPCTSTR)"APITest Good--FXShareApiTest",(LPCTSTR)"FXShareApiTest",MB_OK);
}

FX_SHAREAPI void FXShareApi( DWORD_PTR dwPtr /*= NULL*/ )
{
	MessageBox(NULL,(LPCTSTR)"APITest Good--FXShareApi",(LPCTSTR)"FXShareApi",MB_OK);
}



//
//another project
//use the dll libaray function
//

#define _Dynamic_link
#define _Static_link

#ifdef _Static_link
#include "..\ShareDll\ShareInterface.h"
#pragma comment (lib , "..\\lib\\ShareDll.lib")
#endif

void CFileOperationDlg::ShareDllTestFnc()
{

#ifdef _Dynamic_link
typedef void (*Fn_ShareInterface)(DWORD_PTR dwPtr);
	char lpFile[MAX_PATH] = "\0";
	GetModuleFileName(NULL,lpFile,MAX_PATH);
	char* lpTemp = strrchr(lpFile,'\\');
	if (lpTemp){
		strcpy(lpTemp+1 ,"\0");
	}
	strcat(lpFile,"ShareDll.dll");
	if (_access(lpFile,0)){// mode 0: exist only
		//if the success with the mode,return 0;otherwise -1
		return;
	}
	HMODULE hlib =  LoadLibrary(lpFile);
	if (NULL == hlib ||
		INVALID_HANDLE_VALUE == hlib)
	{
		return;
	}
	if (hlib)
	{
		Fn_ShareInterface ShareApiQ = (Fn_ShareInterface)GetProcAddress(hlib,"ShareApiTest");
		if (ShareApiQ){
			ShareApiQ(NULL);
		}
		Fn_ShareInterface ShareApiTest = (Fn_ShareInterface)GetProcAddress(hlib,"FXShareApiTest");
		if (ShareApiTest){
			ShareApiTest(NULL);
		}
		Fn_ShareInterface ShareApi = (Fn_ShareInterface)GetProcAddress(hlib,"FXShareApi");
		if (ShareApi){
			ShareApi(NULL);
		}
	}

#endif//#ifdef _Dynamic_link

#ifdef _Static_link
	FXShareApiTest(NULL);
	FXShareApi();
#endif

}



注意设置宏_FX_EXPORT_INTERFACE




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值