![]() |
(SST) ShlWAPI.pas Version 1.08 |
---|---|
Developer Reference |
Locates the specified resource type and name in an executable or resource-only module. |
Scope |
---|
Global (i.e. this function can be called/accessed from code in any unit that includes/uses (SST)ShlWAPI.pas). |
Syntax | |
---|---|
function FindResourceWrapW(hInst : HMODULE; lpName : LPCWSTR; lpType : LPCWSTR) : HRSRC; |
Parameters | |
---|---|
hInst [in] | Handle to the executable or resource-only module in which to search for the specified resource. If a non-zero value is specified for this parameter, the function assumes this value to be a handle to the module containing the resource. In this case, the handle should have been acquired by means of one of the LoadLibrary functions (i.e. LoadLibrary or LoadLibraryEx). If zero (0) is specified for this parameter, the function searches for the specified resource type and name in the executable module used to create the process from which the function was called. |
lpName [in] | If the high order word of this parameter is zero, the low-order word is the numerical id of the resource to locate. If the high order word of this parameter is non-zero, this value is assumed to be a pointer to null-terminated, Unicode string naming the resource to find. |
lpType [in] | If the high order word of this parameter is zero, the low-order word is the numerical type id of the resource to locate. If the high order word of this parameter is non-zero, this value is assumed to be a pointer to null-terminated, Unicode string naming the resource type in which to locate the resource with the name or id specified in the previous parameter. |
Return Values |
---|
If the function was able to find a resource with the specidied name
and type in the module referenced by the hInst parameter, it returns a
handle to the resource's info block.
The returned handle can subsequently be used to acquire a handle to
the (actual) resource by means of LoadResource.
In the event of failure the function returns 0.
In this case, additional information on the cause for the failure
may be obtained by calling the Windows API function GetLastError.
|
Remarks |
---|
Although, string parameters are typically used to specify resources that were authored using (user friendly) names, instead of numerical identifiers, (see the Microsoft and/or thid party resource dev. kit doc. for furhter details on how to author and compile resources using one or the other), they can also be used to specify numerical ids by prepending a pound ("#") sign to the string representation of an integer value (e.g. "#713" (without the quotation marks)). This is applicable to both the lpName and lpType parameters. |
The function does not introduce any functionality going beyond that of FindResource, it merely forwards the call to that (Windows API) function. |
As documented in the Microsoft description, this function is not exported by name in any (of the tested and other) ShlWAPI.dlls. However, the same document also states that the function can be referenced by means of its ordinal, 66. The SST implementation of the ShlWAPI unit (SSTShlWAPI.pas) not only declares a function prototype, but also imports the function by this ordinal. Function calls can therefore be implemented without declaring a procedural type, acquiring a pointer to the function's entry point, and subsequently typecasting the returned address. |
In the Requirements table, below, we've stated that the function is supported as of ShlWAPI.dll version 5.0, simply because this is the earliest version we were able to confirm through tests under the operating system versions at our disposal. But, based on the low ordinal value and the fact that the Microsoft documentation explicitly mentions Windows 95, the function is presumably also supported as of the very first releases/updates that installed ShlWAPI.dll (i.e. Internet Explorer 4.0, ShlWAPI.dll version 4.71). |
Example |
---|
PROCEDURE TForm4.TestFindResourceWrapW(Sender : TObject); VAR resmoduleh : THandle; VAR restypeid : INTEGER; VAR resnameid : INTEGER; VAR restypewstr : WideString; VAR resnamewstr : WideString; VAR resinfoblckh : HRSRC; VAR reshandle : HGLOBAL; VAR resdatap : POINTER; VAR resdatasize : DWORD; VAR memstream : TMemoryStream; VAR resicon : TIcon; VAR newinfoline : STRING; BEGIN resmoduleh := 0; restypeid := 0; resnameid := 0; restypewstr := ''; resnamewstr := ''; resinfoblckh := 0; reshandle := 0; resdatap := NIL; resdatasize := 0; memstream := NIL; resicon := NIL; newinfoline := ''; restypeid := 24; //Application Manifest resnameid := 1; resinfoblckh := FindResourceWrapW(resmoduleh, PWChar(resnameid), PWChar(restypeid)); IF resinfoblckh <> 0 THEN BEGIN reshandle := LoadResource(resmoduleh, resinfoblckh); IF reshandle <> 0 THEN resdatap := LockResource(reshandle); IF resdatap <> NIL THEN newinfoline := PChar(resdatap); IF newinfoline <> '' THEN Memo1.Lines.Add(newinfoline) ELSE TestShlWAPIOutputDebugStringWrapW(Sender); END ELSE TestShlWAPIOutputDebugStringWrapW(Sender); restypeid := 0; resnameid := 0; restypewstr := 'GIF'; //Graphics Interchange Format (GIF) image resnamewstr := 'MAINICONGIF'; resinfoblckh := FindResourceWrapW(resmoduleh, PWChar(resnamewstr), PWChar(restypewstr)); IF resinfoblckh <> 0 THEN BEGIN reshandle := LoadResource(resmoduleh, resinfoblckh); IF reshandle <> 0 THEN resdatap := LockResource(reshandle); resdatasize := SizeofResource(resmoduleh, resinfoblckh); memstream := TMemoryStream.Create(); memstream.WriteBuffer(resdatap^, resdatasize); memstream.SaveToFile('MAINICONGIF.Gif'); memstream.Free(); END ELSE TestShlWAPIOutputDebugStringWrapW(Sender); restypewstr := ''; restypewstr := '#3'; //Icon resnamewstr := '#1'; resinfoblckh := FindResourceWrapW(resmoduleh, PWChar(resnamewstr), PWChar(restypewstr)); IF resinfoblckh <> 0 THEN BEGIN reshandle := LoadResource(resmoduleh, resinfoblckh); IF reshandle <> 0 THEN resdatap := LockResource(reshandle); resdatasize := SizeofResource(resmoduleh, resinfoblckh); resicon := TIcon.Create(); resicon.Handle := CreateIconFromResourceEx(resdatap, resdatasize, TRUE, $00030000, 0, 0, LR_DEFAULTCOLOR); resicon.SaveToFile('Delphi5MAINICON.ico'); resicon.Free(); END ELSE TestShlWAPIOutputDebugStringWrapW(Sender); Memo1.Lines.Add(''); END; |
The above code will produce the following output and two files ("MAINICONGIF.Gif" and "Delphi5MAINICON.ico") containing the Delphi (5) icon in Compuserve Gif and Windows icon format. |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="SST.TestShlWAPIFunctions3" type="win32"/> <description>ShlWAPI.dll Function Usage Application.</description> <!--- Comment --> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly> |
See Also |
---|
Windows APIs: FindResource, FindResourceEx, LoadAccelerators, LoadBitmap, LoadCursor, LoadIcon, LoadMenu, LoadResource, LoadString, LockResource, LoadLibrary, LoadLibraryEx, GetLastError, |
Document/Contents version 1.00 Page/URI last updated on May 04, 2022 |
Copyright © Stoelzel Software Technologie (SST) 2010 - 2017 |
Suggestions and comments mail to: webmaster@stoelzelsoftwaretech.com |