我这里有这个代码
program Project1;
{$APPTYPE CONSOLE}
function GetCurrentProcessID : Cardinal; stdcall; external 'kernel32.dll';
begin
writeln (GetCurrentProcessID);
readln;
end.
Run Code Online (Sandbox Code Playgroud)
它告诉我GetCurrentProcessID
无法找到入口点.知道为什么吗?
我甚至试过了
function GetCurrentProcessID : Cardinal; stdcall; external 'kernel32.dll'; name 'GetCurrentProcessID';
Run Code Online (Sandbox Code Playgroud)
没有运气......
我TThread
在我的应用程序中使用,我有很多我想在其中使用的函数.我使用的函数需要一些时间才能完成,因此在线程中使用它们并不理想.这就是为什么我想知道除了复制和粘贴函数/过程之外还有其他方法,然后将(可能注入)我的terminated
标志放入函数中.我不想使用TerminateThread
API!
一个简短的例子:
procedure MyProcedure;
begin
// some work that takes time over a few lines of code
// add/inject terminated flag?!
// try... finally...
end;
procedure TMyThread.Execute;
begin
MyProcedure;
// or copy and paste myprocedure
end;
Run Code Online (Sandbox Code Playgroud)
那么有没有一种有效的方法来编写帮助我terminated
标记的程序/函数?程序/功能也应该是全局的,因此其他功能/程序也可以调用它们.
我有一个功能,在Windows中显示一个气球托盘,它有一个像这样的结构:
const
NIF_INFO = $00000010;
NIIF_NONE = $00000000;
NIIF_INFO = $00000001;
NIIF_WARNING = $00000002;
NIIF_ERROR = $00000003;
type
BalloonData = record
cbSize: DWORD;
Wnd: HWND;
uID: UINT;
uFlags: UINT;
uCallbackMessage: UINT;
hIcon: HICON;
szTip: array[0..MAXCHAR] of AnsiChar;
dwState: DWORD;
dwStateMask: DWORD;
szInfo: array[0..MAXBYTE] of AnsiChar;
uTimeout: UINT;
szInfoTitle: array[0..63] of AnsiChar;
dwInfoFlags: DWORD;
end;
type
TBalloonTimeout = 2..30;
TBalloonIconType = (bitNone, bitInfo, bitWarning, bitError);
function DZBalloonTrayIcon(const Window: HWND; const IconID: Byte; const Timeout: TBalloonTimeout; const BalloonText, BalloonTitle: String; const BalloonIconType: …
Run Code Online (Sandbox Code Playgroud) 我想在delphi中编写一个程序来模拟具有特定速度的移动鼠标指针(类似于AutoIT MouseMove函数).我的代码错误或SetCursorPos在被调用太多次后出现故障.这是我的功能:
procedure MoveMouse ( X, Y, Speed : Integer);
var
P : TPoint;
NewX : Integer;
NewY : Integer;
begin
if X < 0 then exit;
if Y < 0 then exit;
if X > Screen.Height then exit;
if Y > Screen.Width then Exit;
repeat
GetCursorPos(P);
NewX := P.X;
NewY := P.Y;
if P.X <> X then begin
if P.X > X then begin
NewX := P.X - 1;
end else begin
NewX := P.X + 1;
end;
end; …
Run Code Online (Sandbox Code Playgroud) 我现在正在学习 WIN32 ASM,我想知道是否有类似“空闲”无限循环的东西根本不消耗任何资源。基本上我需要一个正在运行的过程来进行实验,如下所示:
loop:
; alternative to sleep...
jmp loop
Run Code Online (Sandbox Code Playgroud)
是否有可能使该过程空闲的东西?
如何sockaddr_in
从套接字句柄中获取关联,以便从中获取端口和地址?或者还有什么关于如何从SocketHandle获取IP和端口?
例如:
function GetSocketPort ( s : TSocket ) : Integer;
var
Addr : sockaddr_in;
begin
// Get sockaddr_in from a socket
end;
function GetSocketAddress ( s : TSocket ) : String;
var
Addr : sockaddr_in;
begin
// Get sockaddr_in from a socket
end;
function ConnectToHost (Host : pchar; Port : Integer) : TSocket;
var
Addr : sockaddr_in;
begin
Addr.sin_family := AF_INET;
Addr.sin_port := htons(Port);
result := Socket(AF_INET, 1, 6);
Addr.sin_addr.S_addr := INET_ADDR(Host);
if not( (Connect(result, Addr, SizeOf(Addr)) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Delphi 中编写我自己的 ThreadManager 单元,到目前为止我已经有了:
unit uThreadManager;
interface
uses
Classes,
Windows;
type
TCustomTThread = class (TThread)
public
TaskData : Pointer;
end;
type
TWorkerThread = class(TObject)
private
TaskDataList : TList;
TaskDataListCrit : TRTLCriticalSection;
function ReadTotalTasks : Integer;
public
constructor Create;
destructor Destroy; override;
property TotalTasks : Integer read ReadTotalTasks;
function AddTask(Thread: TCustomTThread; Data: Pointer) : Integer;
procedure Delete (Index : Integer);
end;
implementation
type
PTaskData = ^TTaskData;
TTaskData = record
Thread : TCustomTThread;
TaskPointer : Pointer;
end;
procedure TWorkerThread.Delete(Index: Integer);
var …
Run Code Online (Sandbox Code Playgroud) 我一直在阅读记录中的"案例",我仍然有一些关于它的开放性问题.(http://www.delphibasics.co.uk/Article.asp?Name=Records)
我用的例子是:
type
TRect = packed record
case Integer of
0: (Left, Top, Right, Bottom: Integer);
1: (TopLeft, BottomRight: TPoint);
end;
Run Code Online (Sandbox Code Playgroud)
这个例子基本上告诉我第一个成员/属性TRect
是Integer
(它Integer
没有名字!).如果这个(未命名!)整数是0
或者1
它只是添加相应的成员:
(0 for Left, Top, Right, Bottom)
(1 for TopLeft, BottomRight)
Run Code Online (Sandbox Code Playgroud)
所以,让我们说内存中有内容我想用这个记录.我公平地添加了一个type
表示指向的新指针TRect
.新记录如下所示:
type
PRect = ^TRect;
TRect = packed record
case Integer of
0: (Left, Top, Right, Bottom: Integer);
1: (TopLeft, BottomRight: TPoint);
end;
Run Code Online (Sandbox Code Playgroud)
所以内容(在内存中)会像这样排序:
First Integer = 0 // determines the case! …
Run Code Online (Sandbox Code Playgroud) 我想直截了当地将默认string
类型声明/覆盖为宽字符串或ansi字符串.
例如,string = WideString;
在Delphi 2009下
如何以及在何处声明/设置/更改默认字符串类型,以便整个项目和IDE保证,它已被特别覆盖?
我想知道从主线程外的VCL控件读取值是否安全.
比方说,我看行之后行(或它的Caption属性)从TMemo/TEdit
从线程控制(没有TThread.Synchronize
),但也取得了一定的TMemo/TEdit
控制已被禁用和/或它的唯一标志已启用读取.
它会安全吗?