您正在查看 "编程资源-winapi" 分类下的文章 2009-06-25 9:27 使用结构或结构数组, 一般是不需要主动分配内存的, 譬如:
var
pts: TPoint;
begin
pts.X := 1;
pts.Y := 2;
ShowMessageFmt('%d,%d', [pts.X, pts.Y]); {1,2}
end;
//结构数组:
|
2009-06-24 22:04 变体结构也就是变体记录, 是一个比较复杂的概念. 专家不提倡使用.
兴趣所致, 我想把它弄明白.
一个最大的无符号整数(Cardinal)是 4294967295, 它的大小是 4 字节, 它的二进制表示是:
11111111 11111111 11111111 11111111
它的低字节的值是 11111111, 也就是十进制的 255
//测试:
var
c: Cardinal;
begin
c :=
|
2009-06-24 21:35
|
在最近的项目中,我们涉及到了“内存对齐”技术。对于大部分程序员来说,“内存对齐”对他们来说都应该是“透明的”。“内存对齐”应该是编译器的 “管辖范围”。编译器为程序中的每个“数据单元”安排在适当的位置上。但是C语言的一个特点就是太灵活,太强大,它允许你干预“内存对齐”。如果你想了解更加底层的秘 | |
2009-06-24 21:34 最近用java做一个网络项目,服务器端软件(C++代码)已经提供了TCP/IP接口,只不过它的数据结构是8字节对齐的,java很难实现,因此我开始研究8字节对齐的内部实现,正好delphi比较熟悉,而且delphi也支持8字节对齐,因此就用delphi来开始研究吧。
我知道,当我们在delphi中定义如下数据结构,在默认情况下应该就是8字节对齐的:
[code] TTest = record
a:char;
b:word;
c:int64;
d:integer;
end;[/code]
现在我定义一个变量,并且赋值,然后看看内存中数据是怎 |
2009-06-17 20:11 Windows API 的数据类型与 Delphi 数据类型对照表
Windows Delphi
数据类型 数据类型 描述
LPSTR PAnsiChar 字符串指针
LPCSTR PAnsiChar 字符串指针
DWORD LongWord 整数
BOOL LongBool 布尔型
PBOOL ^BOOL 指向布尔值的指针
PByte ^Byte 指向字节值的指针
PINT ^Integer 指向整数值的指针
PSingle ^Single |
2007-05-24 12:14 远程控制
program Test
{$APPTYPE CONSOLE}
uses
SysUtils,
windows,
winsock;
{procedure chu();
var
wsadata:TWSADATA;
wversion:WORD;
buff:array[0..4096] of char;
hy,getpass,error,ok,quit:array[0..50] of char;
password:string;
port:integer;
bindserver,getclient:integer;
addrserver:sockaddr_in;
addrclient:PSOCKADDR;
namelen:PInteger;
timeout:pchar;
hreadpipe
|
2007-05-24 12:09 作者 : itren
标题 : 谁动了我的指针?
关键字: 指针 new delete 野指针 调试
分类 : 开发经验
密级 : 参赛
DFW APP2001 译..
谁动了我的指针?
译者序:
本文介绍了一种在调试过程中寻找悬挂指针(野指针)的方法,这种方法是通过对new和delete运算符的重载来实现的。
这种方法不是完美的,它是以调试期的内存泄露为代价来实现的,因为文中出现的代码是绝不能出现在一个最终发布的软件产品中的,只能在调试时使用。
在VC中,在调试环境下,可以简单的通过 |
2007-05-24 12:07 浅谈Object Pascal的指针
C语言之所以强大,以及其自由性,很大部分体现在其灵活的指针运用上。因此,说指针是C语言的灵魂,一点都不为过。同时,这种说法也让很多人产生误解,似乎只有C语言的指针才能算指针。Basic不支持指针,在此不论。其实,Pascal语言本身也是支持指针的。从最初的Pascal发展至今的 Object Pascal,可以说在指针运用上,丝毫不会逊色于C语言的指针。
以下内容分为八个部分,分别是
一、类型指针的定义
二、无类型指针的定义
三、指针的解除引 |
2007-05-24 12:03 #include <windows.h>
char *ExecProcAndOutText(const char *proc )
{
long i, j, k, j1, ret1= 0; char *ret_, *chT1;
const long FILE_BUF= 0x1000;
SECURITY_ATTRIBUTES sa_1= { sizeof(sa_1 ), NULL, TRUE, };
HANDLE hPipeOutputRead, hPipeOutputWrite;
HANDLE hPipeInputRead, hPipeInputWrite;
STARTUPINFO si_1= {
sizeof(si_1 ), NULL, NULL, "",
(DWORD )-1, (DWORD )-1, 0, 0, 80, 0x1000, 0,
|
2007-05-24 12:02 Delphi中编写Windows NT中服务程序
---- Windows NT服务程序不同于一般的运行程序,它不需要NT登录进去,只需要开机进入NT系统便可以运行,一般用于系统服务方面的应用,学会编写NT服务程序对网络管理人员而言是非常重要的,Delphi4.0作为一种高效、快速、强大的开发语言,为开发NT服务程序提供了非常便捷的方法,加上其可视化界面以及与数据库的完美结合,使我们开发与数据库有关的NT服务程序变得非常简单,下面以编写一个NT定期备份程序为例,介绍如何运用Delphi编写Windows NT的服务程序。
---- 打开
|
2006-10-30 17:54 Api拦截并不是一个新的技术,很多商业软件都采用这种技术。对windows的Api函数的拦截,不外乎两种方法,第一种是Mr. Jeffrey Richter 的修改exe文件的模块输入节,种方法,很安全,但很复杂,而且有些exe文件,没有Dll的输入符号的列表,有可能出现拦截不到的情况。第二种方法就是常用的JMP XXX的方法,虽然很古老,却很简单实用。
本文一介绍第二种方法在Win2k下的使用。第二种方法,Win98/me 下因为进入Ring0级的方法很多,有LDT,IDT,Vxd等方法,很容易在内存中动态修改代码,但在Win2k下,这些方法都不能用,写WDM太过复杂,表面上看来很难实现,
其实不然。Win2k为我们提供了一个强大的内存Api操作函数---VirtualProtectEx,WriteProcessMemeory,ReadProcessMemeory,有了它们我们就能在内存中动态修改代码了,其原型为:
BOOL VirtualProtectEx(
HANDLE hProcess, // 要修改内存的进程句柄
|
2006-10-30 17:38 鼠标勾子
Question/Problem/Abstract:
Capture mouse moves and clicks in all System.
Answer:
In this article, you have an example of installation of a hook type Shell at system level.
You will be able to control the movement and button clicks that take place in all Windows, (not only in your application)
As it is a hook at system level, this must go separated in a DLL.
To know more than the operation of the hook, the DLL and the communication between the DLL and our application, take a look to the
article:
http://www.delphi3000.com/articles/article_883.asp
since it is similar to this trick, and I won't repeat the explanations here.
hook's DLL
li |
2006-10-30 17:37 显示CPU频率,内存,主板型号,显卡型号等硬件信息
控件需要可以显示CPU频率,内存,主板型号,显卡型号等硬件信息,还需要显示CPU占用率,GDI,USER资源,内存占用等软件信息,信息越多越好。如果一个控件不行,多个也可!
unit MainDlg;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Registry;
type
TMainForm = class(TForm)
MemoBox: TMemo;
CloseBtn: TButton;
procedure GetOSVersionInfo;
procedure GetDriveNames;
procedure GetDirectories;
procedure GetSystemInfo;
procedure GetDiskInfo;
|
2006-10-30 17:29 得到CPU 闲置时间
Introduction
In general, when we talk about tracking a user's idle time, we are really after the time duration since the user last touched the mouse or keyboard of the system. Unfortunately, the Windows API does not provide us with an easy way of getting this value. However, we can roll our own using the Win32 hooks API.
The approach used here is really a simple one. We intercept the mouse and keyboard activities of the user by hooking into the OS's mouse and keyboard events using the API SetWindowsHookEx(). It is important to note that the hooks we are installing are system-wide. i.e. we receive notification even when our application does not have the focus. This is necessary since we are interested in system-wide user activities, not just in our own application. In these notifications (both keyboard and mouse), we update a common variable that stores the time when the event occurred. Therefore, to get the duration since the last user |
2006-10-30 17:24 得到其他进程子窗体
通过一个父窗体的句柄,递归的枚举它的子窗体,我们可以最终找到需要的子窗体。
用法如下:
nParentHandle: HWnd;
nChildHandle: HWnd;
nParentHandle := FindWindow(nil, 'Notepad');
if nParentHandle <> 0 then
nChildHandle := FindChildWindow(nParentHandle, 'SomeChildEditsClassName');
------函数代码------
var
hwndFindChildWindow : HWND;
function EnumWindowsForFindChildWindowProc(WHandle: HWND; lParam: LPARAM): BOOL; export; stdcall;
const
MAX_WINDOW_NAME_LEN = 80;
var
sTargetClassName: string;
nHandle: HWnd;
sCurrClassName: s
|
| | |