Brandon
2014-02-26 20:47:13
Added Garbage cleanup debug to demonstrate that there are no leaks!
Also made images export the pixel functions in the BGRA format: NOT RGBA!
Images should NOT throw exceptions anymore, make sure to get if their handle is valid or their width and height are greater than 0.
I call it the Riddler library..
Here are 80+ functions to spice up your scripting life and interact directly with the OS and do things natively..
Windows: [ATTACH=CONFIG]26676[/ATTACH]
Linux: [ATTACH=CONFIG]23257[/ATTACH]
Function ReleaseGC(const ptr: Pointer): Boolean;
Function ReleaseGC(const str: String): Boolean; overload;
Function ErrorMessage(Error: UInt32; Throw: Boolean = False): PChar;
Function QuickHammingDistance(const First, Second: String): UInt32;
Function HammingDistance(const First, Second: String): UInt32;
Function LevenshteinDistance(const First, Second: String): UInt32;
Function UTF8ToUTF16(const utf8: AnsiString): PWChar;
Function UTF16ToUTF8(const utf16: UnicodeString): PChar;
Function GetProcessModuleInfo(const ProcessName: String): PChar;
Function EncodeBase64(const Data: String): PChar;
Function DecodeBase64(const Data: String): PChar;
Function CRCGenerateTable: PtrUInt;
Function CRCLookUpTable: PtrUInt;
Function Adler32(const Data: Byte; Size: UInt32): UInt32;
Function CRC32Checksum(const Data: Byte; Size, InitialValue: UInt32 = $EDB88320): UInt32;
Function GetWindowHandle(const WindowName, WindowClass: String): PtrUInt;
Function GetChildWindowHandle(Parent, Child: PtrUInt; const WindowName, ClassName: String): PtrUInt;
Function GetDesktopWindowHandle: PtrUInt;
Procedure GetWindowSize(WindowHandle: PtrUInt; var Width, Height: Integer);
Function GetPID: Integer;
Procedure AppendWindowText(WindowHandle: PtrUInt; const Text: String);
Function WindowHandleFromPoint(p: TPoint): PtrUInt;
Function ChildWindowHandleFromPoint(Parent: PtrUInt; p: TPoint): PtrUInt;
Function FindMainWindow(PID: UInt32): PtrUInt;
Function GetWindowParent(Child: PtrUInt): PtrUInt;
Function SetWindowParent(Parent, Child: PtrUInt): PtrUInt;
Function GetPreviousWindow(WindowHandle: PtrUInt): PtrUInt;
Function GetNextWindow(WindowHandle: PtrUInt): PtrUInt;
Function GetDisplayDevices: PChar;
Function GetPrimaryDisplayDevice: DISPLAY_DEVICE;
Function GetDisplaySettings(Index: Integer): PChar;
Procedure SetDefaultDisplaySettings;
Function SetDisplayResolution(Width, Heignt: Integer): Boolean;
Function CreateMemoryMap(const MapName: String; Size: UInt32): Pointer;
Function OpenMemoryMap(const MapName: String; Size: UInt32): Pointer;
Function CreateNewEvent(lpEventAttributes: ^SECURITY_ATTRIBUTES; bManualReset, bInitialState: Boolean; const EventName: String): PtrUInt;
Function OpenSingleEvent(const EventName: String; InheritHandle: Boolean; dwDesiredAccess: UInt32 = EVENT_ALL_ACCESS; dwMilliseconds: UInt32 = INFINITE): UInt32;
Function SetEventSignal(const EventName: String; Signaled: Boolean): Boolean;
Function DeleteEvent(const EventName: String): Boolean;
Procedure FlipImage(InPtr: Pointer; var OutPtr: Pointer; Width, Height: Integer; BitsPerPixel: UInt32);
Function MessageBoxTimeOut(Parent: PtrUInt; const lpText, lpCaption: String; uType, dwMilliseconds: UInt32; wLanguageID: Word = 0): Integer;
Function ReverseNumber(Number: Int64): Int64;
Function GetEnvironmentVariable(const Variable: String): PChar;
Function SetEnvironmentVariable(const VariableName, VariableValue: String): Boolean;
Function QSort(Base: Pointer; Num, Size: UInt32; Compar: Function(const a, b: Pointer): Integer): Integer;
Procedure SetWindowTransparency(Window: PtrUInt; Transparency: Byte);
Function GetProcessInfo(const ProcessName: String): PROCESSENTRY32;
Function IsProcessRunning(const ProcessName: String): Boolean;
Function ProcessInfoToString(Proc32: PROCESSENTRY32): PChar;
Function GetModulesInfo(ProcessID: UInt32): Array Of MODULEENTRY32;
Function GetModuleInfo(ProcessID: UInt32; const ModuleName: String): MODULEENTRY32;
Function ModuleInfoToString(Mod32: MODULEENTRY32): PChar;
Function RunApplication(const ApplicationName, ApplicationArguments: String; WaitInputIdle: Boolean): Boolean;
Function StartService(const szServiceName: String): Boolean;
Function StopService(const szServiceName: String): Boolean;
Function CreateRegistryKey(Root: Pointer; const SubRoot, KeyName: String; KeyType: REG_KEY_TYPE; const InitialValue: String; samDesired: Integer = 0): Boolean;
Function DeleteRegistryKey(Root: Pointer; const KeyToRemove: String; samDesired: Integer = 0): Boolean;
Function DeleteRegistryValue(Root: Pointer; const SubRoot, KeyToRemove: String; samDesired: Integer = 0): Boolean;
Function SetRegistryKey(Root: Pointer; const SubRoot, KeyToEdit, NewValue: String; KeyType: REG_KEY_TYPE; samDesired: Integer = 0): Boolean;
Function ReadRegistryKey(Root: PtrUInt; const SubRoot, KeyToRead: String; KeyType: REG_KEY_TYPE; var Str: array of char; samDesired: Integer = 0): Integer;
Function GetDriveInfo(const Drive: String; var FreeSpace, TotalSpace: Word; InGigaBytes: Boolean = False): Boolean;
Function GetTypeOfDrive(const Drive: String): PChar;
Function GetLogicalDrivesList(const Drives: array[0..25] of char): Integer;
Function CreateThread(FunctionToPass: Pointer): Integer;
Procedure DetachThread(ThreadID: Integer);
Procedure JoinThread(ThreadID: Integer);
Procedure ClearThreads(Join: boolean);
Function ThreadHardwareConcurrency: Integer;
Function NativeThreadID(ThreadID: Integer): Int64;
Procedure SleepThreadFor(Milliseconds: Integer);
Procedure YieldThread;
Function CreateAsync(FunctionToPass: Pointer): Integer;
Procedure ClearAsync;
Procedure WaitAsync(AsyncID: Integer);
Function WaitForAsync(AsyncID, Milliseconds: Integer): Boolean;
Function CreateLock: Integer;
Procedure RemoveLock(LockID: Integer);
Procedure Lock(LockID: Integer);
Function TryLock(LockID: Integer): Boolean;
Procedure Unlock(LockID: Integer);
Procedure GlobalLock;
Function GlobalTryLock: Boolean;
Procedure GlobalUnlock;
Procedure ClearLocks;
Function CreateImage(Width, Height: Integer): Integer;
Function LoadImage(FilePath: String): Integer;
Function ImageFromPointer(Ptr: Pointer; Width, Height: Integer): Integer;
Function ImageFromCursor: Integer;
Function ImageFromWindow(WndHandle: PtrUInt; X, Y, Width, Height: Integer): Integer;
Procedure DrawToWindow(ImageID: Integer; WndHandle: PtrUInt; X, Y, Width, Height, SourceX, SourceY: Integer = 0; RasterType: Integer = $00CC0020);
Procedure SaveImage(ImageID: Integer; FilePath: String);
Procedure DeleteImage(ImageID: Integer);
Function GetImagePixel(ImageID, X, Y: Integer): Integer;
Function GetImagePixels(ImageID: Integer; var Width, Height: Integer): Pointer;
Procedure SetImagePixel(ImageID, Colour, X, Y: Integer);
Procedure GetImageDimensions(ImageID: Integer; var Width, Height: Integer);
Procedure ClearImages;
Was originally written for Java and C# but meh..


