|
@@ -29,6 +29,8 @@ type
|
|
end;
|
|
end;
|
|
PResHdr = ^TResHdr;
|
|
PResHdr = ^TResHdr;
|
|
|
|
|
|
|
|
+ TLibGetResHdr=function():PResHdr;
|
|
|
|
+
|
|
var
|
|
var
|
|
{$ifdef FPC_HAS_WINLIKERESOURCES}
|
|
{$ifdef FPC_HAS_WINLIKERESOURCES}
|
|
ResHeader : PResHdr; external name 'FPC_RESLOCATION';
|
|
ResHeader : PResHdr; external name 'FPC_RESLOCATION';
|
|
@@ -40,6 +42,31 @@ var
|
|
Private Helper Functions
|
|
Private Helper Functions
|
|
*****************************************************************************)
|
|
*****************************************************************************)
|
|
|
|
|
|
|
|
+function ExtGetResHdr(ModuleHandle : TFPResourceHMODULE):PResHdr;
|
|
|
|
+var
|
|
|
|
+ p:TLibGetResHdr;
|
|
|
|
+ pp:pointer;
|
|
|
|
+begin
|
|
|
|
+ ExtGetResHdr:=nil;
|
|
|
|
+ if ModuleHandle=0 then
|
|
|
|
+ ExtGetResHdr:=ResHeader // internal
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ // 1-st way to get resource location
|
|
|
|
+ p:=TLibGetResHdr(GetProcAddress(ModuleHandle,'rsrc'));
|
|
|
|
+ if p<>nil then // there is public
|
|
|
|
+ ExtGetResHdr:=p();
|
|
|
|
+ if ExtGetResHdr=nil then // try another way
|
|
|
|
+ begin
|
|
|
|
+ // 2-nd way to get resource location
|
|
|
|
+ pp:=GetProcAddress(ModuleHandle,'FPC_RESLOCATION');
|
|
|
|
+ if pp<>nil then
|
|
|
|
+ ExtGetResHdr:=PResHDR(pp^);
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+
|
|
//resource functions are case insensitive... copied from genstr.inc
|
|
//resource functions are case insensitive... copied from genstr.inc
|
|
function ResStrIComp(Str1, Str2 : PChar): SizeInt;
|
|
function ResStrIComp(Str1, Str2 : PChar): SizeInt;
|
|
var
|
|
var
|
|
@@ -135,12 +162,12 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
//Returns a pointer to a name node.
|
|
//Returns a pointer to a name node.
|
|
-function InternalFindResource(ResourceName, ResourceType: PChar):
|
|
|
|
|
|
+function InternalFindResource(ResHdr:PResHdr;ResourceName, ResourceType: PChar):
|
|
PResInfoNode;
|
|
PResInfoNode;
|
|
begin
|
|
begin
|
|
InternalFindResource:=nil;
|
|
InternalFindResource:=nil;
|
|
- if ResHeader=nil then exit;
|
|
|
|
- InternalFindResource:=ResHeader^.rootptr;
|
|
|
|
|
|
+ if ResHdr=nil then exit;
|
|
|
|
+ InternalFindResource:=ResHdr^.rootptr;
|
|
|
|
|
|
InternalFindResource:=BinSearchRes(InternalFindResource,ResourceType);
|
|
InternalFindResource:=BinSearchRes(InternalFindResource,ResourceType);
|
|
if InternalFindResource<>nil then
|
|
if InternalFindResource<>nil then
|
|
@@ -165,6 +192,9 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
(*****************************************************************************
|
|
(*****************************************************************************
|
|
Public Resource Functions
|
|
Public Resource Functions
|
|
*****************************************************************************)
|
|
*****************************************************************************)
|
|
@@ -177,11 +207,13 @@ end;
|
|
Function IntEnumResourceTypes(ModuleHandle : TFPResourceHMODULE; EnumFunc : EnumResTypeProc; lParam : PtrInt) : LongBool;
|
|
Function IntEnumResourceTypes(ModuleHandle : TFPResourceHMODULE; EnumFunc : EnumResTypeProc; lParam : PtrInt) : LongBool;
|
|
var ptr : PResInfoNode;
|
|
var ptr : PResInfoNode;
|
|
tot, i : integer;
|
|
tot, i : integer;
|
|
|
|
+ res_hdr:PResHdr;
|
|
begin
|
|
begin
|
|
IntEnumResourceTypes:=False;
|
|
IntEnumResourceTypes:=False;
|
|
- if ResHeader=nil then exit;
|
|
|
|
- tot:=ResHeader^.rootptr^.ncounthandle+ResHeader^.rootptr^.idcountsize;
|
|
|
|
- ptr:=ResHeader^.rootptr^.subptr;
|
|
|
|
|
|
+ res_hdr:=ExtGetResHdr(ModuleHandle);
|
|
|
|
+ if res_hdr=nil then exit;
|
|
|
|
+ tot:=res_hdr^.rootptr^.ncounthandle+res_hdr^.rootptr^.idcountsize;
|
|
|
|
+ ptr:=res_hdr^.rootptr^.subptr;
|
|
IntEnumResourceTypes:=true;
|
|
IntEnumResourceTypes:=true;
|
|
i:=0;
|
|
i:=0;
|
|
while i<tot do
|
|
while i<tot do
|
|
@@ -194,10 +226,12 @@ end;
|
|
Function IntEnumResourceNames(ModuleHandle : TFPResourceHMODULE; ResourceType : PChar; EnumFunc : EnumResNameProc; lParam : PtrInt) : LongBool;
|
|
Function IntEnumResourceNames(ModuleHandle : TFPResourceHMODULE; ResourceType : PChar; EnumFunc : EnumResNameProc; lParam : PtrInt) : LongBool;
|
|
var ptr : PResInfoNode;
|
|
var ptr : PResInfoNode;
|
|
tot, i : integer;
|
|
tot, i : integer;
|
|
|
|
+ res_hdr:PResHdr;
|
|
begin
|
|
begin
|
|
IntEnumResourceNames:=False;
|
|
IntEnumResourceNames:=False;
|
|
- if ResHeader=nil then exit;
|
|
|
|
- ptr:=ResHeader^.rootptr;
|
|
|
|
|
|
+ res_hdr:=ExtGetResHdr(ModuleHandle);
|
|
|
|
+ if res_hdr=nil then exit;
|
|
|
|
+ ptr:=res_hdr^.rootptr;
|
|
|
|
|
|
ptr:=BinSearchRes(ptr,ResourceType);
|
|
ptr:=BinSearchRes(ptr,ResourceType);
|
|
if ptr=nil then exit;
|
|
if ptr=nil then exit;
|
|
@@ -216,9 +250,12 @@ end;
|
|
Function IntEnumResourceLanguages(ModuleHandle : TFPResourceHMODULE; ResourceType, ResourceName : PChar; EnumFunc : EnumResLangProc; lParam : PtrInt) : LongBool;
|
|
Function IntEnumResourceLanguages(ModuleHandle : TFPResourceHMODULE; ResourceType, ResourceName : PChar; EnumFunc : EnumResLangProc; lParam : PtrInt) : LongBool;
|
|
var ptr : PResInfoNode;
|
|
var ptr : PResInfoNode;
|
|
tot, i : integer;
|
|
tot, i : integer;
|
|
|
|
+ res_hdr:PResHdr;
|
|
begin
|
|
begin
|
|
IntEnumResourceLanguages:=False;
|
|
IntEnumResourceLanguages:=False;
|
|
- ptr:=InternalFindResource(ResourceName,ResourceType);
|
|
|
|
|
|
+ res_hdr:=ExtGetResHdr(ModuleHandle);
|
|
|
|
+ if res_hdr=nil then exit;
|
|
|
|
+ ptr:=InternalFindResource(res_hdr,ResourceName,ResourceType);
|
|
if ptr=nil then exit;
|
|
if ptr=nil then exit;
|
|
|
|
|
|
tot:=ptr^.idcountsize;
|
|
tot:=ptr^.idcountsize;
|
|
@@ -235,18 +272,21 @@ end;
|
|
Function IntFindResource(ModuleHandle: TFPResourceHMODULE; ResourceName,
|
|
Function IntFindResource(ModuleHandle: TFPResourceHMODULE; ResourceName,
|
|
ResourceType: PChar): TFPResourceHandle;
|
|
ResourceType: PChar): TFPResourceHandle;
|
|
var ptr : PResInfoNode;
|
|
var ptr : PResInfoNode;
|
|
|
|
+ res_hdr: PresHdr;
|
|
begin
|
|
begin
|
|
IntFindResource:=0;
|
|
IntFindResource:=0;
|
|
- ptr:=InternalFindResource(ResourceName,ResourceType);
|
|
|
|
|
|
+ res_hdr:=ExtGetResHdr(ModuleHandle);
|
|
|
|
+ if res_hdr=nil then exit;
|
|
|
|
+ ptr:=InternalFindResource(res_hdr,ResourceName,ResourceType);
|
|
if ptr=nil then exit;
|
|
if ptr=nil then exit;
|
|
|
|
|
|
//first language id
|
|
//first language id
|
|
ptr:=ptr^.subptr;
|
|
ptr:=ptr^.subptr;
|
|
if ptr^.ncounthandle=0 then
|
|
if ptr^.ncounthandle=0 then
|
|
begin
|
|
begin
|
|
- ResHeader^.handles[ResHeader^.usedhandles]:=PtrUint(ptr);
|
|
|
|
- inc(ResHeader^.usedhandles);
|
|
|
|
- ptr^.ncounthandle:=ResHeader^.usedhandles;
|
|
|
|
|
|
+ res_hdr^.handles[res_hdr^.usedhandles]:=PtrUint(ptr);
|
|
|
|
+ inc(res_hdr^.usedhandles);
|
|
|
|
+ ptr^.ncounthandle:=res_hdr^.usedhandles;
|
|
end;
|
|
end;
|
|
IntFindResource:=ptr^.ncounthandle;
|
|
IntFindResource:=ptr^.ncounthandle;
|
|
end;
|
|
end;
|
|
@@ -256,9 +296,12 @@ Function IntFindResourceEx(ModuleHandle: TFPResourceHMODULE; ResourceType,
|
|
const LANG_NEUTRAL = 0;
|
|
const LANG_NEUTRAL = 0;
|
|
LANG_ENGLISH = 9;
|
|
LANG_ENGLISH = 9;
|
|
var nameptr,ptr : PResInfoNode;
|
|
var nameptr,ptr : PResInfoNode;
|
|
|
|
+ res_hdr: PResHdr;
|
|
begin
|
|
begin
|
|
IntFindResourceEx:=0;
|
|
IntFindResourceEx:=0;
|
|
- nameptr:=InternalFindResource(ResourceName,ResourceType);
|
|
|
|
|
|
+ res_hdr:=ExtGetResHdr(ModuleHandle);
|
|
|
|
+ if res_hdr=nil then exit;
|
|
|
|
+ nameptr:=InternalFindResource(res_hdr,ResourceName,ResourceType);
|
|
if nameptr=nil then exit;
|
|
if nameptr=nil then exit;
|
|
|
|
|
|
//try exact match
|
|
//try exact match
|
|
@@ -278,27 +321,31 @@ begin
|
|
|
|
|
|
if ptr^.ncounthandle=0 then
|
|
if ptr^.ncounthandle=0 then
|
|
begin
|
|
begin
|
|
- ResHeader^.handles[ResHeader^.usedhandles]:=PtrUint(ptr);
|
|
|
|
- inc(ResHeader^.usedhandles);
|
|
|
|
- ptr^.ncounthandle:=ResHeader^.usedhandles;
|
|
|
|
|
|
+ res_hdr^.handles[res_hdr^.usedhandles]:=PtrUint(ptr);
|
|
|
|
+ inc(res_hdr^.usedhandles);
|
|
|
|
+ ptr^.ncounthandle:=res_hdr^.usedhandles;
|
|
end;
|
|
end;
|
|
IntFindResourceEx:=ptr^.ncounthandle;
|
|
IntFindResourceEx:=ptr^.ncounthandle;
|
|
end;
|
|
end;
|
|
|
|
|
|
Function IntLoadResource(ModuleHandle: TFPResourceHMODULE; ResHandle: TFPResourceHandle): TFPResourceHGLOBAL;
|
|
Function IntLoadResource(ModuleHandle: TFPResourceHMODULE; ResHandle: TFPResourceHandle): TFPResourceHGLOBAL;
|
|
|
|
+var res_hdr: PResHdr;
|
|
begin
|
|
begin
|
|
IntLoadResource:=0;
|
|
IntLoadResource:=0;
|
|
- if ResHeader=nil then exit;
|
|
|
|
- if (ResHandle<=0) or (ResHandle>ResHeader^.usedhandles) then exit;
|
|
|
|
- IntLoadResource:=TFPResourceHGLOBAL(PResInfoNode(ResHeader^.handles[ResHandle-1])^.subptr);
|
|
|
|
|
|
+ res_hdr:=ExtGetResHdr(ModuleHandle);
|
|
|
|
+ if res_hdr=nil then exit;
|
|
|
|
+ if (ResHandle<=0) or (ResHandle>res_hdr^.usedhandles) then exit;
|
|
|
|
+ IntLoadResource:=TFPResourceHGLOBAL(PResInfoNode(res_hdr^.handles[ResHandle-1])^.subptr);
|
|
end;
|
|
end;
|
|
|
|
|
|
Function IntSizeofResource(ModuleHandle: TFPResourceHMODULE; ResHandle: TFPResourceHandle): LongWord;
|
|
Function IntSizeofResource(ModuleHandle: TFPResourceHMODULE; ResHandle: TFPResourceHandle): LongWord;
|
|
|
|
+var res_hdr: PResHdr;
|
|
begin
|
|
begin
|
|
IntSizeofResource:=0;
|
|
IntSizeofResource:=0;
|
|
- if ResHeader=nil then exit;
|
|
|
|
- if (ResHandle<=0) or (ResHandle>ResHeader^.usedhandles) then exit;
|
|
|
|
- IntSizeofResource:=PResInfoNode(ResHeader^.handles[ResHandle-1])^.idcountsize;
|
|
|
|
|
|
+ res_hdr:=ExtGetResHdr(ModuleHandle);
|
|
|
|
+ if res_hdr=nil then exit;
|
|
|
|
+ if (ResHandle<=0) or (ResHandle>res_hdr^.usedhandles) then exit;
|
|
|
|
+ IntSizeofResource:=PResInfoNode(res_hdr^.handles[ResHandle-1])^.idcountsize;
|
|
end;
|
|
end;
|
|
|
|
|
|
Function IntLockResource(ResData: TFPResourceHGLOBAL): Pointer;
|
|
Function IntLockResource(ResData: TFPResourceHGLOBAL): Pointer;
|