我是DELPHI的初学者,现在要写一个简单的DLL,提供一个函数,输入两个字符串参数,返回一个字符串,请高手提供一个简单的例子!!谢谢!!
解决方案 »
- 有没有for delphi7的apro呢?
- KOL的tkolimageshow的bug?
- Undeclared identifier: 'Sender'
- (小菜问题)关于DBGrid浏览位置的问题....
- 我是新手,一个关于窗体的问题
- DBGRIDEH 怎么设置行高? 呵呵
- 如何为程序动态添加控件,并且动态的为该控件添加事件!!!
- 《Delphi7 高效数据库程序设计》的简单问题
- 关于绘图!
- 请问:在delphi中关键字overload ,override具体有什么意思?
- 请问有关delphi7中的水晶报表控件ucrpeds和ucrpe32的用法?比如调用水晶报表的统计和打印予览及打印功能等
- 请问如何设置和显示放音和录音音量的大小
我是初学者啊,您能不能提供完整的一个例子啊!!
library Project2;
uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas';
Exports GetStr;{$R *.RES}
begin
end.
unit Unit1;
interface
uses sysutils;
function GetStr(s1:pChar;s2:pChar):pChar; StdCall ;
implementation
function GetStr(s1:pChar;s2:pChar):pChar;
begin
GetMem(Result,Length(s1)+Length(s2));
Result:=StrCat(Result,s1);
Result:=StrCat(Result,s2);
end;
end.
以下是调用
unit Unit6;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
function GetStr(s1:pchar;s2:pchar):pchar;stdcall;external 'Project2.dll'
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage( GetStr('fdfd','fff'));
end;
end.
您的方法我先试一试!!
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
SysUtils,
Classes;{$R *.res}
function ReadPort1(Port:integer):integer;stdcall;
var
a:integer;
begin
a:=port+1;
Result:=a;
end;function ReadPort(Port:WORD):BYTE;stdcall;
var
B:BYTE;
begin
asm
MOV DX, Port;
IN AL, DX;
MOV B, AL;
end;
Result:=B;
end;procedure WritePort(Port:WORD;ConByte:BYTE);stdcall;
begin
ASM
MOV DX, Port;
MOV AL, ConByte;
OUT DX, AL;
END;
end;exports
readport1,
readport,
WritePort;
begin
end.
您的代码编译不过啊!!
=========================
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
editIN: TEdit;
btDouble: TButton;
btTriple: TButton;
Label1: TLabel;
Label2: TLabel;
editRESULT: TEdit;
Edit1: TEdit;
Label3: TLabel;
Edit2: TEdit;
Label4: TLabel;
Edit3: TEdit;
Label5: TLabel;
Button1: TButton;
procedure btDoubleClick(Sender: TObject);
procedure btTripleClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
//
function Double(N:Integer):Integer;
stdcall;external'myDLL.dll';
function Triple(N:Integer):Integer;
stdcall;external'myDLL.dll';
function GetStr(A1:OleVariant;A2:OleVariant):OleVariant;
stdcall;external'myDLL.dll';
{$R *.dfm}procedure TForm1.btDoubleClick(Sender: TObject);
begin
if editIN.Text<>'' then
begin
editResult.Text:=
IntToStr(Double(StrToInt(editIN.Text)));
end;
end;procedure TForm1.btTripleClick(Sender: TObject);
begin
if editIN.Text<>'' then
begin
editResult.Text:=
IntToStr(Triple(StrToInt(editIN.Text)));
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Edit3.Text:=GetStr(Edit1.Text,Edit2.Text);
end;end.
清查收吧,还有问题可以再找我。
===============================
我这段时间在CSDN上见到很多兄弟
都提这个问题:“怎样在DLL上传递String
的参数,在我这个范例中我已经作了很容易
明白的例子”如果哪位需要的都可以跟我联系!
===========================================
我来帮你们回答!
您的范例已经收到,先谢了,对于在DLL中使用一个窗体或者是一个VCL控件,又该怎么办呢??
unit6是一个新的工程的单元,是用来测试dll的。
to:lgqTiger(【老虎】)
您的范例已经收到,先谢了,对于在DLL中使用一个窗体或者是一个VCL控件,又该怎么办呢??
==============================先作一个带窗体的unit,然后再在DLL中uses,试试吧?
[email protected]
邮箱为:[email protected]
谢谢老虎