Brief: I am looking for the correct Declare for SHGetLocalizedName
I need to get the localized name of special folder items on Windows. Unfortunately, the FolderItem.DisplayName does not provide it. So I decided I need to resort to calling a Windows API to help out. I Googled and determined SHGetLocalizedName to be, what I need. I later found, that this function likely does not provide me with what I was looking for, but rather, where I need to look, in order to find what I need.
So I changed strategy and successfully used SHGetFileInfoW.
I still would like to know why I could not get SHGetLocalizedName to even return something other than different kinds of (Windows API) error messages. Its definition is somewhat strange, as one parameter is specified as UINT cch (no pointer, no [out]) but according to the description returning a value:
SHSTDAPI SHGetLocalizedName(
[in] PCWSTR pszPath,
[out] PWSTR pszResModule,
UINT cch,
[out] int *pidsRes
);
cchType: UINT
When this function returns, contains the size of the string, in WCHARs, at pszResModule.
So, how is the Declare statement for this function supposed to look like?
I created a project where you can see what I came up with, and possibly as a starting point for your own investigation. I have tried variants of what is currently there, but, as I said, never managed to get back a display name (or a path to a dll or exe I need to extract the resource from).
For those who do not want to download the project, or can spot my error in the Declare statement right away, here it is:
Declare Function SHGetLocalizedName Lib "Shell32" (pszPath As WString, ByRef szResModule As Ptr, cch As UInt32, ByRef pidsRes As Ptr) As Int32
Dim DisplayName As String
Dim pszPath As WString = path
Dim szResModule As New MemoryBlock(261*2) // MAX_PATH + 1 as WideStr
Dim pszResModule As Ptr = szResModule
Dim cch As UInt32
Dim midsRes As New MemoryBlock(4)
Dim pidsRes As Ptr = midsRes
Dim idsRes As Int32
Dim hResult As Int32
hResult = SHGetLocalizedName(pszPath, pszResModule, cch, pidsRes)
FolderDisplayName.zip (10.5 KB)