Delphi 中PChar()函数的用法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Delphi 中PChar()函数的用法相关的知识,希望对你有一定的参考价值。

lpClassName
[in] Pointer to a null-terminated string that specifies the class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero.
If lpClassName points to a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names.

If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.

lpWindowName
[in] Pointer to a null-terminated string that specifies the window name (the window 's title). If this parameter is NULL, all window names match.

以上是对findwindow函数参数的解释,从中可以看出,通过类型查找窗口句柄的话,首先该类必须由RegisterClass或RegisterClassEx注册过,或者是属于预定义的控件类。
参考技术A 一般做dll调用,或者调用dll时用得最多,他的意思是转换字符串为指针供程序调用 参考技术B PChar是一个指针, 它的大小只有32位. 定义时由Delphi自动填0. 要将PChar作为字符串
使用的话必须自己分配内存用完必须自己释放. PChar型字符串由#0表示字符串结尾
Delphi所提供的相关PChar字符串的操作都是判断#0来决定字符串的结尾的。
因为PChar是指针,所以它能指向任何地方(也就是说它不一定非要指向字符串不可).
把一个String赋值给PChar只是将String中保存具体字符串的内存的地址给PChar
变量. 当然也可以把Char数组第一个元素的地址给PChar.

pchar不是函数,而是数据类型。pchar是个指针类型,指向#0结尾的字符串,比如你看到如下代码:

var s:String;
begin
xxx(pchar(s));//把s强制转换为pchar(string本身也是指针)
//..
end;
参考技术C 转换指针为PChar型指针

以上是关于Delphi 中PChar()函数的用法的主要内容,如果未能解决你的问题,请参考以下文章

Delphi的shellexecute用法

在delphi中,这个PChar指针的作用是啥?

delphi DrawText 的用法

请问delphi中pchar()是个啥函数,返回啥值?

delphi WaitForSingleObject 函数 用法

delphi7 PChar 转为 String 弹出乱码