http://njhuadian.com/Mpeg4Decoder.dll
http://njhuadian.com/Mpeg4Decoder.h
http://njhuadian.com/Mpeg4Decoder.lib文件在上面下载,我调用的时间总是提示找不到入口地址,请高手帮忙看一下什么原因,给一个最简单成功调用的例子
http://njhuadian.com/Mpeg4Decoder.h
http://njhuadian.com/Mpeg4Decoder.lib文件在上面下载,我调用的时间总是提示找不到入口地址,请高手帮忙看一下什么原因,给一个最简单成功调用的例子
RVA Ord. Hint Name
-------- ---- ---- ----
00004DA0 1 0000 ??0CMpeg4Decoder@@QAE@XZ
00004DC0 2 0001 ??1CMpeg4Decoder@@QAE@XZ
00004CD0 3 0002 ??4CMpeg4Decoder@@QAEAAV0@ABV0@@Z
00005250 4 0003 ?BeginSaveToFile@CMpeg4Decoder@@QAEHPAD@Z
000052F0 5 0004 ?CaptureFrameToBmp@CMpeg4Decoder@@QAE_NPAD@Z
00005360 6 0005 ?CloseSerial232Device@CMpeg4Decoder@@QAE_NXZ
000051D0 7 0006 ?ConnectStream@CMpeg4Decoder@@QAE_NHH@Z
00005240 8 0007 ?DisConnectStream@CMpeg4Decoder@@QAEXXZ
.....
(记得以前CSDN的BCB版中有人问过此类问题,BCB怎样调VC++带类的DLL)
解决的方法是,用VC++重新写一DLL,调用上面DLL中的函数,而导出函数用
extern "C" 来定义,这样delphi就可调用了(只是多了一个DLL,作为接口)
// dll.cpp : Defines the entry point for the DLL application.
//#include "stdafx.h"
#include "Mpeg4Decoder.h"
#pragma comment (lib,"Mpeg4Decoder.lib")BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
extern "C" __declspec(dllexport) void Initm_pDecoder()
{
m_pDecoder = new CMpeg4Decoder();
}
extern "C" __declspec(dllexport) void UnInitm_pDecoder()
{
delete m_pDecoder ;
}extern "C" __declspec(dllexport) bool InitDecoder()
{
return m_pDecoder->InitDecoder();}
extern "C" __declspec(dllexport) void SetUserName(char*sName)
{
m_pDecoder->SetUserName(sName);
}
//...其它的自已定义
编译成dll.dll,并拷放delphi项目的目录中
2.在delphi中写:unit test;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;procedure Initm_pDecoder;cdecl;
procedure UnInitm_pDecoder;cdecl;
function InitDecoder:boolean;cdecl;
procedure SetUserName(sName:pchar);cdecl;
var
Form1: TForm1;implementation
{$R *.dfm}
procedure Initm_pDecoder;cdecl; external 'dll.dll';
procedure UnInitm_pDecoder;cdecl; external 'dll.dll';
function InitDecoder:boolean;cdecl;external 'dll.dll';
procedure SetUserName(sName:pchar);cdecl;external 'dll.dll';procedure TForm1.Button1Click(Sender: TObject);
begin
Initm_pDecoder;
InitDecoder;
SetUserName('test'); // ...
UnInitm_pDecoder;
end;end.
其中
Initm_pDecoder/UnInitm_pDecoder是我自已加的,
Initm_pDecoder主要为VC++初始化m_pDecoder类
因为m_pDecoder是类指针,只能在VC中初始化
同理UnInitm_pDecoder为释放m_pDecoder用
-------------------------------------------------------------------------------------
在vc里面用extern "C"修饰,必须是__stdcal调用方式,必须使用def文件来生成输出函数借口
--------------------------------------------------------------------------------------
在delphi中调用时,可以是__cdecl方式,且不用def文件,我一直这样用的(更方便些)
上面的程序当然也经过调试,没有问题