delphi7 调用c++ 写的类

解决方案 »

  1.   

    以前做过DLL中BCB5调用D6的类,不知现在还行不行
    class ITalking
    {
      public:
     virtual void __stdcall SetComplete();
    }TTalking = class
      pbulic
        procedure SetComplete();virtual;stdcall;
    end;
      

  2.   

    // op的vmt兼容c++的vmt, 调用倒是可以,
    // 不过怎么把类的信息传过来是个问题,
    // 我只想到在dll中另外加输出类函数的方法
    // delphi中的声明
    const VMTTest = 'G:\PROJECTS\VMTTest\Debug\VMTTest.dll';
    type
      CTest = class
      public
        // 因为仅是一个定义,所以必须为abstract方法。
        procedure HelloWorld; virtual; stdcall; abstract;
      end;  TCreateTest = function: CTest; stdcall;procedure TForm1.Button1Click(Sender: TObject);
    var C: CTest;
    var H: THandle;
    var CreateTest: TCreateTest;
    begin
      H := LoadLibrary(VMTTest);
      @CreateTest := GetProcAddress(H, '_CreateTest@0');
      if @CreateTest <> nil then
      begin
        C := CreateTest;
        if C <> nil then
          C.HelloWorld
        else
          Caption := 'nil';
      end
      else
        Caption := 'fail';
      FreeLibrary(H);
    end;//vc中的声明
    class CTest{
    public:
    virtual void __stdcall HelloWorld(){
    MessageBox(0, "Hello, World", "Test", 0);
                      delete this; // 加这行代码仅为方便删除自己
    };
    // TODO: add your methods here.
    };// 下面这个函数用来输出类
    extern "C" _declspec(dllexport) CTest * __stdcall CreateTest()
    {
    return new CTest();
    };
      

  3.   

    我建议写为OCX,这样应该比较方便。