forked from Sovos-Compliance/direct-bpl-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlTypes.pas
77 lines (63 loc) · 3.49 KB
/
mlTypes.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{*******************************************************************************
* Vladimir Georgiev, 2014 *
* *
* Types used by the "Memory Loader" units *
* *
*******************************************************************************}
{$I MlDefines.inc}
unit mlTypes;
interface
uses
SysUtils, Windows, Classes;
type
/// A helper type for the handles used by the emulated functions
/// Currently equal to the original HMODULE, but can be changed to another type to avoid
/// mixing it with handles returned by the original APIs
TLibHandle = type HMODULE;
/// Exception classes raised by the "ML" library
EMlError = class(Exception);
EMlLibraryLoadError = class(EMlError);
/// A Callback function that is called when a library being loaded needs to load a dependent library
/// The value set in aLoadAction defines how the dependent library should be loaded
/// laDiscard - don't load the library
/// laHardDrive - load the library with the standard LoadLibrary Windows API
/// laStream - load the library from the stream passed in aStream (which has to be freed later)
/// laLoaded - the library is loaded by the callback and the handle returned to the caller
TLoadAction = (laHardDisk, laStream, laDiscard, laLoaded);
TMlLoadDependentLibraryEvent = procedure(const aLibName, aDependentLib: String; var aLoadAction: TLoadAction; var
aStream: TStream; var aFreeStream: Boolean; var aLoadedHandle: TLibHandle) of object;
{$IFDEF VER130}
EOSError = class(Exception);
TValidatePackageProc = function (Module: HMODULE): Boolean;
{$ENDIF VER130}
type
TLoadLibraryFunc = function (lpLibFileName: PChar) : HMODULE; stdcall;
TLoadLibraryExFunc = function (lpLibFileName: PChar; hFile: THandle; dwFlags: DWORD): HMODULE; stdcall;
TFreeLibraryFunc = function (hModule: HMODULE) : BOOL; stdcall;
TGetProcAddressFunc = function (hModule: HMODULE; lpProcName: LPCSTR) : FARPROC; stdcall;
TFindResourceFunc = function (hModule: HMODULE; lpName, lpType: PChar) : HRSRC; stdcall;
TLoadResourceFunc = function (hModule: HMODULE; hResInfo: HRSRC) : HGLOBAL; stdcall;
TSizeofResourceFunc = function (hModule: HMODULE; hResInfo: HRSRC) : DWORD; stdcall;
TGetModuleFileNameFunc = function (hModule: HINST; lpFilename: PChar; nSize: DWORD) : DWORD; stdcall;
TGetModuleHandleFunc = function (lpModuleName: PChar) : HMODULE; stdcall;
TLoadPackageFunc = function (const Name: string; AValidatePackage: TValidatePackageProc = nil): HMODULE;
TUnloadPackageProc = procedure (Module: HMODULE);
procedure ReportError(aExceptionClass: ExceptClass; const aMsg: String; aLastError: Cardinal);
implementation
/// Helper procedure for raising exceptions
procedure ReportError(aExceptionClass: ExceptClass; const aMsg: String; aLastError: Cardinal);
begin
{$IFDEF ML_ERROR_RAISE}
{$IFDEF ML_TRAP_EXCEPTION}
try
{$ENDIF ML_TRAP_EXCEPTION}
raise aExceptionClass.Create(aMsg);
{$IFDEF ML_TRAP_EXCEPTION}
except
end;
{$ENDIF ML_TRAP_EXCEPTION}
{$ELSE}
SetLastError(aLastError);
{$ENDIF ML_ERROR_RAISE}
end;
end.