MYDLL.H 中的定义代码:class CQqAthmApp : public CWinApp
{
public:
  unsigned long qqe;
  CQqAthmApp();
  int Test();
  Encode(unsigned long * ,unsigned long * ,unsigned long * );
};MYDLL.CPP的代码:
CQqAthmApp::CQqAthmApp()
{
 // TODO: add construction code here,
 // Place all significant initialization in InitInstance
}//////////
// The one and only CQqAthmApp object
CQqAthmApp::EnCode(unsigned long * a,unsigned long * b, unsigned long * c)
{
  MessageBox(0,"进入函数","追踪",0);
  //从DELPHI传递进来的参数在这里变为空.
  //出现非法操作....
}CQqAthmApp theApp;CQqAthmApp::Test()
{
  return 2312;
}
delphi代码:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
 Pint = ^LongWord;type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private  public
    { Public declarations }
  end;function Encode(a:Pint;b:Pint;c:pint):pint;cdecl;external 'MyDll.dll' name 'EnCode';var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var a,b,c:Pint;
begin
 a^:=222;
 b^:=333;
 c^:=444;
 EnCode(a,b,c);
end;end.
程序错误一堆堆 ,试过很多方法.我该如何把delphi的数据类型给C++的指针类型
EnCode函数是把进去的三个参数乱算一堆然后改变第三个参数c,可是进去的数字都是空的....
dll的代码是对的,Test函数返回成功各位高手帮帮忙否?

解决方案 »

  1.   

    你可以导出类,但是导出类不能直接被delphi使用,需要导出函数。或者利用导出函数返回接口让Delphi使用。// {74008C37-2D8F-4c61-AE65-847D62DA0663}
    static const CLSID CLSID_CoQqAthmApp = 
    { 0x74008c37, 0x2d8f, 0x4c61, { 0xae, 0x65, 0x84, 0x7d, 0x62, 0xda, 0x6, 0x63 } };
    // {7889D47C-4747-470e-A6A6-872C7F99BA60}
    static const IID IID_IQqAthmApp = 
    { 0x7889d47c, 0x4747, 0x470e, { 0xa6, 0xa6, 0x87, 0x2c, 0x7f, 0x99, 0xba, 0x60 } };DECLARE_INTERFACE_(IQqAthmApp,IUnknown)
    {
    STDMETHOD(QueryInterface) (THIS_ REFIID riid,LPVOID FAR* ppvObj) PURE;
    STDMETHOD_(ULONG,AddRef) (THIS) PURE;
    STDMETHOD_(ULONG,Release) (THIS) PURE;
    STDMETHOD_(INT,Encode) (THIS_ LPDWORD a,LPDWORD b,LPDWORD c) PURE;
    };实现这个接口。然后导出一个访问这个接口的方法。Delphi里面
    type IQqAthmApp=interface
    ['{7889D47C-4747-470e-A6A6-872C7F99BA60}']
    function (a,b,c:PDWORD):PDWORD;stdcall;
    end;
    通过导出方法获得接口然后通过接口调用。
    p.s. 楼主你函数没返回值是个很不好的习惯
      

  2.   

    8好意思。写掉了函数名:
    function Encode(a,b,c:PDWORD):PDWORD;stdcall;
      

  3.   

    var a,b,c:Pint;
    begin
    a^:=222;
    b^:=333;
    c^:=444;a、b、c都是指向未知的地方,随便赋值容易引发异常
      

  4.   

    var
      a, b, c: LongWord;
    begin
      a := 222;
      b := 333;
      c := 444;
      EnCode(@a, @b, @c);
    end;