首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

Dll调用能够返回执行结果,但提示invalid pointer operation异常

2012-04-16 
Dll调用能够返回执行结果,但提示invalid pointer operation错误程序部分Delphi(Pascal) codeunit Unit1in

Dll调用能够返回执行结果,但提示invalid pointer operation错误
程序部分

Delphi(Pascal) code
unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;type  TForm1 = class(TForm)    lbl1: TLabel;    lbl2: TLabel;    Edt_Str: TEdit;    Edt_Key: TEdit;    lbl3: TLabel;    Edt_CryptA: TEdit;    btn1: TButton;    btn2: TButton;    lbl4: TLabel;    Edt_CryptB: TEdit;    lbl5: TLabel;    Edt_StrA: TEdit;    Edt_StrB: TEdit;    lbl6: TLabel;    procedure btn1Click(Sender: TObject);    procedure btn2Click(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end;  TKeyByte = array[0..5] of Byte;  TDesMode = (dmEncry, dmDecry);var  Form1: TForm1;  function EncryStr(Str, Key: string): string;external 'Encypt.dll' name 'EncryStr';  function DecryStr(Str, Key: string): string;external 'Encypt.dll' name 'DecryStr';  function EncryStrHex(Str, Key: string): string;external 'Encypt.dll' name 'EncryStrHex';  function DecryStrHex(Str, Key: string): string;external 'Encypt.dll' name 'DecryStrHex';implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);begin  Edt_CryptA.Text:=EncryStr(Edt_Str.Text,Edt_Key.Text);  Edt_CryptB.Text:=EncryStrHex(Edt_Str.Text,Edt_Key.Text);end;procedure TForm1.btn2Click(Sender: TObject);begin  Edt_StrA.Text:=DecryStr(Edt_CryptA.Text,Edt_Key.Text);  Edt_StrB.Text:=DecryStrHex(Edt_CryptB.Text,Edt_Key.Text);end;end.

DLL部分
Delphi(Pascal) code
library Encypt;{ Important note about DLL memory management: ShareMem must be the  first unit in your library's USES clause AND your project's (select  Project-View Source) USES clause if your DLL exports any procedures or  functions that pass strings as parameters or function results. This  applies to all strings passed to and from your DLL--even those that  are nested in records and classes. ShareMem is the interface unit to  the BORLNDMM.DLL shared memory manager, which must be deployed along  with your DLL. To avoid using BORLNDMM.DLL, pass string information  using PChar or ShortString parameters. }uses  ShareMem,  SysUtils,  Classes,  DES in 'DES.pas';{$R *.res}  exports    EncryStr,    DecryStr,    EncryStrHex,    DecryStrHex;beginend.


DES部分代码较多,我就不写了,DES部分没有问题,因为如果不使用DLL方式直接调用程序不会报错。

[解决办法]
把borlndmm.dll拷贝到程序所在目录呢?

热点排行