问两个有点难度的问题:怎样声明及使用API 和 ActiveX DLL?

LoveDana 2002-08-21 10:10:50
譬如,我们要获取计算机的名字,我们使用GetComputerName API,但是,具体怎样声明,怎样使用呢?请给出具体的例子,谢谢!

还有,ActiveX DLL呢?我一引用类库,就产生一大堆的代码,不知道怎样用啊!
请给出具体的例子,谢谢!
...全文
29 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
liao_yy 2002-08-21
  • 打赏
  • 举报
回复
例子:在D6运行通过!!!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
StaticText1: TStaticText;
StaticText2: TStaticText;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
s:array[1..127] of char;
i:DWord;
begin
GetComputerName(@s,i);
//获取计算机名
Edit1.Text:=s;
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
if SetComputerName(PChar(Edit2.text)) then
//更改计算机名成功
ShowMessage('您的计算机已改名为'+Edit2.Text)
else
ShowMessage('改名失败');
end;

end.
liao_yy 2002-08-21
  • 打赏
  • 举报
回复
UP
dream_looker 2002-08-21
  • 打赏
  • 举报
回复
声明WindowsAPI:function GetComputerName(lpBuffer: PChar; var nSize: DWORD): BOOL; stdcall;实际上,大部分Windows API包含在Windows.pas中,只要用use包括即可直接调用。但注意字符串要使用PChar类型,可以将string类型转换为pChar类型。查pChar,帮助中有例子,最后要加上stdcall,表示该函数采用windows API的标准调用方式,而不是Delphi缺省的pascal调用方式。
rainsea 2002-08-21
  • 打赏
  • 举报
回复
例如:输入ShellExecute();
然后按F1,看这个函数在哪个单元,然后uses 这个单元。
就可以直接调用api函数了。

你可以把ActiveX 注册为控件,然后调用控件
qq:35735257
netlib 2002-08-21
  • 打赏
  • 举报
回复
1、uses windows;
2、uses Comobj;
Bitter_fish 2002-08-21
  • 打赏
  • 举报
回复
有一个单元以声名API,好像是window,打开它看。
先注册ActiveX DLL,然后用createobject();
hfycl 2002-08-21
  • 打赏
  • 举报
回复
up
LoveDana 2002-08-21
  • 打赏
  • 举报
回复
楼上,非常感谢!我已经理解了!

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧