vc动态库要注意 extern c,要注意把依赖的动态库也一块儿放进来
1、 extern c问题
导出ffplay动态库,发现 m_FunMain_abc = (fmain_abc)GetProcAddress(m_hDllPlay, "main_abc"); 一直是0,
#ifdef CSPPRODUCTIONTOOL_EXPORTS #define CSPPRODUCTIONTOOL_API __declspec(dllexport) #else #define CSPPRODUCTIONTOOL_API __declspec(dllimport) #endif CSPPRODUCTIONTOOL_API int main_abc(void* hwnd);
后来用下面网址的命令 DUMPBIN /EXPORTS dll_file_name.dll,看跟能正常调用的不太一样
https://blog.csdn.net/g5dsk/article/details/6680698
Dump of file ffplayDll.dll File Type: DLL Section contains the following exports for ffplayDll.dll 00000000 characteristics 60F023A3 time date stamp Thu Jul 15 20:01:39 2021 0.00 version 1 ordinal base 1 number of functions 1 number of names ordinal hint RVA name 1 0 00011762 ?main_abc@@YAHPAX@Z = @ILT+1885(?main_abc@@YAHPAX@Z) Summary 1000 .data 3000 .idata 7000 .rdata 2000 .reloc 1000 .rsrc 1C000 .text 10000 .textbss
改成
extern "C"{
CSPPRODUCTIONTOOL_API int main_abc(void* hwnd);
}
后ok了
Microsoft (R) COFF/PE Dumper Version 12.00.21005.1 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file ffplayDll.dll File Type: DLL Section contains the following exports for ffplayDll.dll 00000000 characteristics 60F0E5ED time date stamp Fri Jul 16 09:50:37 2021 0.00 version 1 ordinal base 1 number of functions 1 number of names ordinal hint RVA name 1 0 000112FD main_abc = @ILT+760(_main_abc) Summary 1000 .data 3000 .idata 7000 .rdata 2000 .reloc 1000 .rsrc 1C000 .text 10000 .textbss
2、LoadLibrary 问题
因为动态库还依赖于ffmpeg 和 sdl库,sdl 库没放进去,所以m_hDllPlay 一直是0
CString strDLLPlayPath = strmyINIFilePath + _T("ffplayDll.dll");// _T("F:\ffplayDll.dll");
if (NULL == m_hDllPlay)
m_hDllPlay = LoadLibrary(strDLLPlayPath);