|
-
Jan 5th, 2013, 06:06 AM
#7
Thread Starter
Lively Member
LoadImage issue #2
 Originally Posted by Bonnie West
For all values from &H8000 to &HFFFF, the literal must be closed off with the type-declaration character for Long (& ampersand) to explicitly type it as such, lest it will be treated as a negative Integer.
Yes, normally I do add the ampersand to all hex values to ensure, that it is not a negative Integer.
But I used the ApiViewer to generate the LR_SHARED declaration and just pasted it without any change...
Using a data type other than a Variant doesn't mean you're safe from implicit type conversion.
That is true - but at least I can see the needed type by pressing Ctrl+i.
Unfortunatelly I have another issue regarding LoadImage:
In both projects (linked in my first post), the code is using the API ExtractIconEx to get an icon from an EXE or DLL file:
Code:
Public Function LoadFromLibrary(ByVal Library As String, ByVal lIconIndex As Long) As Boolean
Call FreeIconMemory
Call ExtractIconEx(StrPtr(Library), lIconIndex, m_hIcon, ByVal 0&, 1)
LoadFromLibrary = CBool(m_hIcon)
End Function
But with this API we can get either the system large or system small icon only.
And we cannot use a resource name or ordinal to retrive the right icon - we have to use the index instead.
Additionally this API is not capable to load bitmap resources like LoadImage.
Therefore I wanted to apply LoadImage here too. - But following code is not working:
Code:
Public Function LoadFromLibrary2(ByVal Library As String, _
ByRef ResNameOrOrdinal As Variant, _
Optional Size As IconSizeEnum = IS_First) As Boolean
' Destroy the previous Icon, if a new one is loaded
Call FreeIconMemory
Dim hMod As Long
hMod = LoadLibrary(StrPtr(Library))
Call MsgBox("hMod = " & hMod & vbCrLf & _
"Err.LastDllError = " & Err.LastDllError)
hMod = GetModuleHandle(StrPtr(Library)) 'no FreeLibrary!
Call MsgBox("hMod = " & hMod & vbCrLf & _
"Err.LastDllError = " & Err.LastDllError)
Dim lpszName As Long
Select Case VarType(ResNameOrOrdinal)
Case vbString: lpszName = StrPtr(ResNameOrOrdinal)
Case vbInteger: lpszName = CLng(ResNameOrOrdinal)
Case Else: Call Err.Raise(5&) 'Invalid procedure call or argument
End Select
Dim tSize As Size
tSize = GetSize(Size)
' Do not use LR_SHARED for images that have non-standard sizes,
' that may change after loading, or that are loaded from a file.
m_hIcon = LoadImage(hMod, _
lpszName, _
IMAGE_ICON, _
tSize.cx, _
tSize.cy, _
LR_DEFAULTCOLOR)
Call MsgBox("m_hIcon = " & m_hIcon & vbCrLf & _
"Err.LastDllError = " & Err.LastDllError)
Call FreeLibrary(hMod)
LoadFromLibrary2 = CBool(m_hIcon)
End Function
I tried it with GetModuleHandle, like recommended in the MSDN article to LoadImage and with LoadLibrary, in case the module has not been loaded yet.
Both APIs return the same handle, but the first call to one of them (it doesn't matter if GetModuleHandle or LoadLibrary is called first) does also show a dll error: 1402
The LoadImage API then returns 0 and gives the dll error 1813. (I tried it with "shell32.dll" for Library and the value 130 for ResNameOrOrdinal)
Maybe there is no icon with ordinal 130... How can I check, which icons are in there?
With ResHacker I am just seeing lots of folders under "Icon" with a number as name containing an icon with the name "1033".
Under "Icon Group" I can find some ordinal information, but I still see the above mentiond result, if I use them.
I don't see my mistake - I did everything like stated in the MSDN article (at least I think so)...
Can you please help me here too?
Last edited by NeedHelp!; Jan 5th, 2013 at 06:10 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|