我现在使用delphi 做出dll了,使用delphi 能够正确调用,但是使用vb怎么样调用呢
delphi中的dll 的函数
function DecodeBase64(Source:ShortString):ShortString; stdcall;
function EncodeBase64(Source:ShortString):ShortString;stdcall;
在delphi 的调用方法
function DecodeBase64(Source:ShortString):ShortString; stdcall;external 'Project2.dll';
function EncodeBase64(Source:ShortString):ShortString;stdcall;
external 'Project2.dll';怎样将 这段delphi 更改成vb调用的呢
这个是我的vb代码
Type ShortString
wLength As Integer
szBuf As String * 255 '或者szBuf(0 to 254) As Byte ShortString 只支持255 个字符
End TypeDeclare Function EncodeBase64 Lib "Project2.dll" Alias "DecodeBase64 " (ByVal Source As ShortString) As ShortString
Declare Function DecodeBase64 Lib "Project2.dll" Alias "DecodeBase64 " (ByVal Source As ShortString) As ShortString
Private Sub Command1_Click()
Text2.Text = DecodeBase64(Text2.Text)
End SubPrivate Sub Command2_Click()
Text3.Text = DecodeBase64(Text2.Text)
End Sub
提示:compile error:
user-defined try may not be passed byval这样写的话
Declare Function DecodeBase64 Lib "'Project2.dll'" Alias "DecodeBase64 " (Byval Source As String) As String
Declare Function EncodeBase64Lib "'Project2.dll'" Alias "EncodeBase64" (Byval Source As String) As String
错误提示是:
"0x0000000"指令引用的"0x0000000"内存,该内存不能为"read".
要终止程序,请单击"确定".
要调试程序,请单击"取消".
delphi中的dll 的函数
function DecodeBase64(Source:ShortString):ShortString; stdcall;
function EncodeBase64(Source:ShortString):ShortString;stdcall;
在delphi 的调用方法
function DecodeBase64(Source:ShortString):ShortString; stdcall;external 'Project2.dll';
function EncodeBase64(Source:ShortString):ShortString;stdcall;
external 'Project2.dll';怎样将 这段delphi 更改成vb调用的呢
这个是我的vb代码
Type ShortString
wLength As Integer
szBuf As String * 255 '或者szBuf(0 to 254) As Byte ShortString 只支持255 个字符
End TypeDeclare Function EncodeBase64 Lib "Project2.dll" Alias "DecodeBase64 " (ByVal Source As ShortString) As ShortString
Declare Function DecodeBase64 Lib "Project2.dll" Alias "DecodeBase64 " (ByVal Source As ShortString) As ShortString
Private Sub Command1_Click()
Text2.Text = DecodeBase64(Text2.Text)
End SubPrivate Sub Command2_Click()
Text3.Text = DecodeBase64(Text2.Text)
End Sub
提示:compile error:
user-defined try may not be passed byval这样写的话
Declare Function DecodeBase64 Lib "'Project2.dll'" Alias "DecodeBase64 " (Byval Source As String) As String
Declare Function EncodeBase64Lib "'Project2.dll'" Alias "EncodeBase64" (Byval Source As String) As String
错误提示是:
"0x0000000"指令引用的"0x0000000"内存,该内存不能为"read".
要终止程序,请单击"确定".
要调试程序,请单击"取消".
解决方案 »
- 高分。关于lookupcombox的!
- pbl 的调用
- 关于ADOQuery1.Locate的使用问题!
- 怎样汇总啊?
- sql server中如何字符型字段内容转入为日期型字段中?
- TDateTimePicker中,如何返回 '2000-02-02' 这样格式的字符串?如何得到值啊?另,能否同时输入时间?
- 如何实现对u盘的写保护
- Delphi7编译问题~~~~~~~
- 请问在delphi中如何向rs232串口写入数据啊???
- 收集delphi的函数api,自己制作api
- 以下这断代码在w2000下执行正常,在XP下执行会无限等待,好象是停在WaitForSingleObject(piProcess.hProcess, INFINITE);
- 如何访问用程序实现域用户登陆?
用PChar
library Project2;{ 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;
const
//BaseTable为BASE64码表
BaseTable:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
{$R *.res}
function FindInTable(CSource:char):integer;stdcall;
begin
result:=Pos(string(CSource),BaseTable)-1;
end;//编码函数
function EncodeBase64(Source:ShortString):ShortString;stdcall;
var
Times,LenSrc,i:integer;
x1,x2,x3,x4:char;
xt:byte;
begin
result:='';
LenSrc:=length(Source);
if LenSrc mod 3 =0 then Times:=LenSrc div 3
else Times:=LenSrc div 3 + 1;
for i:=0 to times-1 do
begin
if LenSrc >= (3+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(Ord(Source[2+i*3]) shl 2) and 60;
xt:=xt or (ord(Source[3+i*3]) shr 6);
x3:=BaseTable[xt+1];
xt:=(ord(Source[3+i*3]) and 63);
x4:=BaseTable[xt+1];
end
else if LenSrc>=(2+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(ord(Source[2+i*3]) shl 2) and 60;
x3:=BaseTable[xt+1];
x4:='=';
end else
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
x2:=BaseTable[xt+1];
x3:='=';
x4:='=';
end;
result:=result+x1+x2+x3+x4;
end;
end;
exports
EncodeBase64;
//解码函数
function DecodeBase64(Source:ShortString):ShortString; stdcall;
var
SrcLen,Times,i:integer;
x1,x2,x3,x4,xt:byte;
begin
result:='';
SrcLen:=Length(Source);
Times:=SrcLen div 4;
for i:=0 to Times-1 do
begin
x1:=FindInTable(Source[1+i*4]);
x2:=FindInTable(Source[2+i*4]);
x3:=FindInTable(Source[3+i*4]);
x4:=FindInTable(Source[4+i*4]);
x1:=x1 shl 2;
xt:=x2 shr 4;
x1:=x1 or xt;
x2:=x2 shl 4;
result:=result+chr(x1);
if x3= 64 then break;
xt:=x3 shr 2;
x2:=x2 or xt;
x3:=x3 shl 6;
result:=result+chr(x2);
if x4=64 then break;
x3:=x3 or x4;
result:=result+chr(x3);
end;
end;
exports
DecodeBase64;
{//编码函数
function TestDll(Source:ShortString ):ShortString ;stdcall;
var
Times,LenSrc,i:integer;
x1,x2,x3,x4:char;
xt:byte;
begin
result:=''; LenSrc:=length(Source);
if LenSrc mod 3 =0 then Times:=LenSrc div 3
else Times:=LenSrc div 3 + 1;
for i:=0 to times-1 do
begin
if LenSrc >= (3+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(Ord(Source[2+i*3]) shl 2) and 60;
xt:=xt or (ord(Source[3+i*3]) shr 6);
x3:=BaseTable[xt+1];
xt:=(ord(Source[3+i*3]) and 63);
x4:=BaseTable[xt+1];
end
else if LenSrc>=(2+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(ord(Source[2+i*3]) shl 2) and 60;
x3:=BaseTable[xt+1];
x4:='=';
end else
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
x2:=BaseTable[xt+1];
x3:='=';
x4:='=';
end;
result:=result+x1+x2+x3+x4;
end;
end;///
exports
TestDll;
}
begin
end.主程序调用(当然是静态的,动态的,我在修改)
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
Edit3: TEdit;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
function DecodeBase64(Source:ShortString):ShortString; stdcall;external 'Project2.dll';
function EncodeBase64(Source:ShortString):ShortString;stdcall;
external 'Project2.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
//Edit1.Text:=IntToStr(TestDll(2));end;procedure TForm1.Button2Click(Sender: TObject);
begin
//edit2.text:=EncodeBase64(edit1.text);
edit2.text:=EncodeBase64(edit1.text);
end;procedure TForm1.Button3Click(Sender: TObject);
begin
edit3.text:=DecodeBase64 (edit2.text);
end;end.
但是更改成pchar的话 解密的就不对了啊
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;
const
//BaseTable为BASE64码表
BaseTable:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
{$R *.res}
function FindInTable(CSource:char):integer;stdcall;
begin
result:=Pos(string(CSource),BaseTable)-1;
end;//编码函数
function EncodeBase64(aSource:pchar):pchar;stdcall;
var
Times,LenSrc,i:integer;
x1,x2,x3,x4:char;
xt:byte;
Source:string;
begin
result:='';
Source:=string(aSource);
LenSrc:=length(Source);
if LenSrc mod 3 =0 then Times:=LenSrc div 3
else Times:=LenSrc div 3 + 1;
for i:=0 to times-1 do
begin
if LenSrc >= (3+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(Ord(Source[2+i*3]) shl 2) and 60;
xt:=xt or (ord(Source[3+i*3]) shr 6);
x3:=BaseTable[xt+1];
xt:=(ord(Source[3+i*3]) and 63);
x4:=BaseTable[xt+1];
end
else if LenSrc>=(2+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(ord(Source[2+i*3]) shl 2) and 60;
x3:=BaseTable[xt+1];
x4:='=';
end else
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
x2:=BaseTable[xt+1];
x3:='=';
x4:='=';
end;
result:=pchar(result+x1+x2+x3+x4);
end;
end;
exports
EncodeBase64;
//解码函数
function DecodeBase64(aSource:pchar):pchar; stdcall;
var
SrcLen,Times,i:integer;
x1,x2,x3,x4,xt:byte;
Source:string;
begin
result:='';
Source:=string(aSource);
SrcLen:=Length(Source);
Times:=SrcLen div 4;
for i:=0 to Times-1 do
begin
x1:=FindInTable(Source[1+i*4]);
x2:=FindInTable(Source[2+i*4]);
x3:=FindInTable(Source[3+i*4]);
x4:=FindInTable(Source[4+i*4]);
x1:=x1 shl 2;
xt:=x2 shr 4;
x1:=x1 or xt;
x2:=x2 shl 4;
result:=pchar(result+chr(x1));
if x3= 64 then break;
xt:=x3 shr 2;
x2:=x2 or xt;
x3:=x3 shl 6;
result:=pchar(result+chr(x2));
if x4=64 then break;
x3:=x3 or x4;
result:=pchar(result+chr(x3));
end;end;
exports
DecodeBase64;
这个我作了更改.没有问题了.
function DecodeBase64(Source:pchar):pchar; stdcall;external 'Project2.dll';
function EncodeBase64(Source:pchar):pchar;stdcall;
external 'Project2.dll';
这个是delphi 调用没有问题.但是在vb里面怎样调用呢