/// // /*************************************************** 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 #ifdef _FX_EXPORT_INTERFACE #define FX_SHAREAPI extern "C" __declspec(dllexport) #else #define FX_SHAREAPI extern "C" __declspec(dllimport) #endif //error LNK2019: 无法解析的外部符号 "public: void __thiscall ShareInterface::Init(void)" (?Init@ShareInterface@@QAEXXZ), //该符号在函数 "public: void __thiscall CFileOperationDlg::ShareDllTestFnc(void)" (?ShareDllTestFnc@CFileOperationDlg@@QAEXXZ) 中被引用 //class /*__declspec(dllexport)*/ ShareInterface class __declspec(dllexport) ShareInterface { public: ShareInterface(void); ~ShareInterface(void); public: void Init(); int RunShare(DWORD_PTR dwPtr , int nType = 0); protected: char* m_lpName; int m_nIndex; }; FX_SHAREAPI void FXShareApiTest(DWORD_PTR dwPtr = NULL); FX_SHAREAPI void FXShareApi(DWORD_PTR dwPtr = NULL); FX_SHAREAPI int FXStart(DWORD_PTR dwPtr, int nType = 0); FX_SHAREAPI BOOL FXStop(DWORD_PTR dwPtr, LPARAM lparam,int nType = 0); FX_SHAREAPI ShareInterface* FXShareInterface(DWORD_PTR& dwPtr);
// //ShareInterface.cpp // #include "StdAfx.h" #include "ShareInterface.h" ShareInterface::ShareInterface(void) { m_nIndex = 0X01; m_lpName = NULL; m_lpName = new char[65]; strcpy(m_lpName,"ShareInterface"); } ShareInterface::~ShareInterface(void) { m_nIndex =0; m_lpName = NULL; } void ShareInterface::Init() { MessageBox(NULL,(LPCTSTR)"ShareInterface::Init()",(LPCTSTR)"ShareInterface",MB_OK); } int ShareInterface::RunShare( DWORD_PTR dwPtr , int nType /*= 0*/ ) { Init(); return 1; } FX_SHAREAPI void FXShareApiTest( DWORD_PTR dwPtr ) { MessageBox(NULL,(LPCTSTR)"APITest Good--FXShareApiTest",(LPCTSTR)"FXShareApiTest",MB_OK); } FX_SHAREAPI void FXShareApi( DWORD_PTR dwPtr ) { MessageBox(NULL,(LPCTSTR)"APITest Good--FXShareApi",(LPCTSTR)"FXShareApi",MB_OK); } FX_SHAREAPI ShareInterface* FXShareInterface( DWORD_PTR& dwPtr ) { ShareInterface* pShareInterface = new ShareInterface(); if (pShareInterface){ //dwPtr = (DWORD_PTR)pShareInterface; return pShareInterface; } return NULL; } FX_SHAREAPI int FXStart( DWORD_PTR dwPtr, int nType /*= 0*/ ) { MessageBox(NULL,(LPCTSTR)"FXStart",(LPCTSTR)"FXStart",MB_OK); return 1; } FX_SHAREAPI BOOL FXStop( DWORD_PTR dwPtr, LPARAM lparam,int nType /*= 0*/ ) { MessageBox(NULL,(LPCTSTR)"FXStop",(LPCTSTR)"FXStop",MB_OK); return TRUE; }
// //other cpp call the Interface in "ShareInterface" // #define _Dynamic_link #define _Static_link #ifdef _Static_link #include "..\ShareDll\ShareInterface.h" #pragma comment (lib , "..\\lib\\ShareDll.lib") #endif #ifdef _Dynamic_link typedef void (*pfn_FXShareApiTest)( DWORD_PTR dwPtr ); typedef void (*pfn_FXShareApi)(DWORD_PTR dwPtr); typedef int (*pfn_FXStart)(DWORD_PTR dwPtr, int nType); typedef BOOL (*pfn_FXStop)(DWORD_PTR dwPtr, LPARAM lparam,int nType); typedef ShareInterface* (*pfn_FXShareInterface)(DWORD_PTR& dwPtr); //pfn_FXShareApiTest FXShareApiTest =NULL; //pfn_FXShareApi FXShareApi =NULL; //pfn_FXStart FXStart =NULL; //pfn_FXStop FXStop =NULL; //pfn_FXShareInterface FXShareInterface =NULL; pfn_FXShareInterface pFXShareInterface =NULL; #define GETAPI(func)\ func = (pfn_##func)GetProcAddress(hlib,#func); #endif void CFileOperationDlg::ShareDllTestFnc() { #ifdef _Dynamic_link typedef void (*Fn_ShareInterface)(DWORD_PTR dwPtr); typedef ShareInterface* (*FX_Interface)(LPARAM 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) { //GETAPI(FXShareApiTest) //GETAPI(FXShareApi) //GETAPI(FXStart) //GETAPI(FXStop) //GETAPI(FXShareInterface) 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); } FX_Interface FXShareInterface = (FX_Interface)GetProcAddress(hlib,"FXShareInterface"); if (FXShareInterface){ ShareInterface* pShareInterface = FXShareInterface(NULL); if (pShareInterface) { pShareInterface->Init(); pShareInterface->RunShare(NULL); } } } #endif//#ifdef _Dynamic_link #ifdef _Static_link FXShareApiTest(NULL); FXShareApi(); #endif }
/error LNK2019: 无法解析的外部符号 "public: void __thiscall ShareInterface::Init(void)" (?Init@ShareInterface@@QAEXXZ),
//该符号在函数 "public: void __thiscall CFileOperationDlg::ShareDllTestFnc(void)" (?ShareDllTestFnc@CFileOperationDlg@@QAEXXZ) 中被引用
//class /*__declspec(dllexport)*/ ShareInterface