http://njhuadian.com/Mpeg4Decoder.dll
http://njhuadian.com/Mpeg4Decoder.h
http://njhuadian.com/Mpeg4Decoder.lib文件在上面下载,我调用的时间总是提示找不到入口地址,请高手帮忙看一下什么原因,给一个最简单成功调用的例子

解决方案 »

  1.   

    我看了一下,该DLL导出的VC的类,delphi是不能找不到入口地址的,用tdum看看它的导出函数就知了
     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,作为接口)
      

  2.   

    1.建一VC DLL项目, 如DLL.dsw内容如下:
    // 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.
      

  3.   

    这只是一个方法,函数定义很多要你自已去写,C++的常量也要换成delphi的方式
    其中
    Initm_pDecoder/UnInitm_pDecoder是我自已加的,
    Initm_pDecoder主要为VC++初始化m_pDecoder类
    因为m_pDecoder是类指针,只能在VC中初始化
    同理UnInitm_pDecoder为释放m_pDecoder用
      

  4.   

    在vc里面用extern "C"修饰,必须是__stdcal调用方式,必须使用def文件来生成输出函数借口(dllexport关键字的做法我没弄成功过,后来懒得研究了),你的代码俺就不看了,做到了就绝对不可能无法调用,当然还有其他原因,比如结构体不一致(字节对齐问题,建议全按1字节对齐),参数入栈方式不一致(比如你用了fastcall方式),对象引用(这个我就不说了,两者之间几乎没有任何共通点,打算这样用的人嘿嘿,自己专研吧)。另外c++里面的指针,可以在delphi里面直接用var修饰,也可以用指针,还有一些细节问题,比如什么资源问题啦,狗屎问题啦,就自行体会啦,我也讲不了那么多。
      

  5.   

    to : muroachanf(菜鸟中的霸王)
    -------------------------------------------------------------------------------------
      在vc里面用extern "C"修饰,必须是__stdcal调用方式,必须使用def文件来生成输出函数借口
    --------------------------------------------------------------------------------------
    在delphi中调用时,可以是__cdecl方式,且不用def文件,我一直这样用的(更方便些)
    上面的程序当然也经过调试,没有问题
      

  6.   

    把.H的头文件,改写成.pas。不过很麻烦,汗~。
      

  7.   

    如果使用导出类可能不行,最好还是把导出类改成到处函数,或者com我以前也是过导出类数据结构不符合调用要求,接口不统一,最好改写成com
      

  8.   

    把它改写成函数的形式咯,导出类的dll对其他语言的调用不是很兼容阿。找不到接口是自然的