1. delphi的pdword和dword之间的关系问题
tmpval:=dword(value);这句的意思是把value强制转换成dword类型,主要看value是什么类型,如果value是一个指针类型,那么这句的的意思就是返回指针指向的地址。
pdword(tmpptr)^:=$91这句其实和tmpptr^:=$91一样,因为tmpptr本来就是pdword类型的指针,如果tmpptr是无类型指针(pointer)才需要这样转换一下。
象这样的类型Delphi还有很多,比如String和PString,Integer和PInteger等,当然你也可以自己定义
2. Delphi URLDownloadToFile参数详解
URLDownloadToFile可以查MSDN
HRESULT URLDownloadToFile(
LPUNKNOWN pCaller,
LPCTSTR szURL,
LPCTSTR szFileName,
DWORD dwReserved,
LPBINDSTATUSCALLBACK lpfnCB
);
在Delphi中的例子
在used 中加入urlmon
function DownloadFile(Source, Dest: string): Boolean;
begin
try
Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;
except
Result := False;
end;
end;
3. Delphi中windows.pas的readFile函数
从文件中读出数据。与lread函数相比,这个函数要明显灵活的多。该函数能够操作通信设备、管道、套接字以及邮槽
返回值
Long,非零表示成功,零表示失败。会设置GetLastError。如启动的是一次异步读操作,则函数会返回零值,并将ERROR_IO_PENDING设置成GetLastError的结果。如结果不是零值,但读入的字节数小于nNumberOfBytesToRead参数指定的值,表明早已抵达了文件的结尾
参数表
参数 类型及说明
hFile Long,文件的句柄
lpBuffer Any,用于保存读入数据的一个缓冲区
nNumberOfBytesToRead Long,要读入的字符数
lpNumberOfBytesRead Long,从文件中实际读入的字符数
lpOverlapped OVERLAPPED,如文件打开时指定了FILE_FLAG_OVERLAPPED,那么必须用这个参数引用一个特殊的结构。那个结构定义了一次异步读取操作。否则,应将这个参数设为NULL(将函数声明成ByVal As Long,并传递零值)
4. Delphi读取内存怎么读取1个字节
读取内存数据通常使用 ReadProcessMemory 函数,其原型定义如下:
BOOL ReadProcessMemory(
HANDLE hProcess, // handle of the process whose memory is read
LPCVOID lpBaseAddress, // address to start reading
LPVOID lpBuffer, // address of buffer to place read data
DWORD nSize, // number of bytes to read
LPDWORD lpNumberOfBytesRead // address of number of bytes read
);其中 nSize 参数指定读取数据的字节数。
因此,读取内存1个字节示例代码如下:
var
v : byte;
Num : Cardinal;
begin
ReadProcessMemory(processHandle, $00ff0011, @v, sizeof(v), Num);
end;
5. delphi 多线程中如何得到线程句柄
如果你的多线程是用TThread实现的,属性ThreadID可以得到指定线程的句柄如果你是通过BeginThread运行的线程函数,可以通过返回值ThreadID得到BeginThread(SecurityAttributes: Pointer; StackSize: LongWord; ThreadFunc: TThreadFunc; Parameter: Pointer; CreationFlags: LongWord; var ThreadId: LongWord): Integer;如果你是通过CreateThread创建的,也可以通过返回值ThreadID得到HANDLE CreateThread( LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to thread security attributes DWORD dwStackSize, // initial thread stack size, in bytes LPTHREAD_START_ROUTINE lpStartAddress, // pointer to thread function LPVOID lpParameter, // argument for new thread DWORD dwCreationFlags, // creation flags LPDWORD lpThreadId // pointer to returned thread identifier ); 如果想得到当前运行的线程的句柄用楼上的方法。
转载请注明出处51数据库 » delphilpdword