在delphi中,怎么调用api函数?

ady2001 2001-07-19 10:24:47
在delphi中,怎么调用api函数?
比如说:
int MessageBox(
HWND hWnd, // handle to owner window
LPCTSTR lpText, // text in message box
LPCTSTR lpCaption, // message box title
UINT uType // message box style
);
怎么解决参数问题?
...全文
63 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jabmoon 2002-02-02
  • 打赏
  • 举报
回复
use一下单元,然后直接用就行了,很方便
duancy 2002-02-02
  • 打赏
  • 举报
回复
以下是一个调用API获得用户名的例子:
procedure TForm1.Button1Click(Sender: TObject);
var
pcUser : PChar;
dwUSize : DWORD;
begin
dwUSize := 21; // user name can be up to 20 characters
GetMem( pcUser, dwUSize ); // allocate memory for the string
try
if Windows.GetUserName( pcUser, dwUSize ) then
edit1.Text := pcUser
finally
FreeMem( pcUser ); // now free the memory allocated for the string
end;
end;
coldljy 2001-07-19
  • 打赏
  • 举报
回复
e.g.
messagebox(Handle,'Hello,World!','Hi',MB_OK);

ZeeGee 2001-07-19
  • 打赏
  • 举报
回复
Delphi中,WinAPI函数已经预先在几个Unit里申明好了,直接调用即可,一般是这么几个Unit:
Windows, Messages, ShellAPI等等
关于类型问题,Delphi中也定义了几乎全部的类型如HWND,UINT,等等,不过LPCTSTR需要用PChar代替,如PChar(MyStr),常量字符串可由编译器自动转化为PChar类型,无需转换PChar类型可用StrPas函数转化为String类型
myxfang 2001-07-19
  • 打赏
  • 举报
回复
直接调用 uses windows
用pchar()转化

1,183

社区成员

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

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