#include #include #include Global Const $RT_ACCELERATOR = 9 Global Const $RT_ANICURSOR = 21 Global Const $RT_ANIICON = 22 Global Const $RT_BITMAP = 2 Global Const $RT_CURSOR = 1 Global Const $RT_DIALOG = 5 Global Const $RT_DLGINCLUDE = 17 Global Const $RT_FONT = 8 Global Const $RT_FONTDIR = 7 Global Const $RT_GROUP_CURSOR = ($RT_CURSOR + 11) Global Const $RT_ICON = 3 Global Const $RT_GROUP_ICON = ($RT_ICON + 11) Global Const $RT_HTML = 23 Global Const $RT_MANIFEST = 24 Global Const $RT_MENU = 4 Global Const $RT_MESSAGETABLE = 11 Global Const $RT_PLUGPLAY = 19 Global Const $RT_RCDATA = 10 Global Const $RT_STRING = 6 Global Const $RT_VERSION = 16 Global Const $RT_VXD = 20 Func ResGet($ResType,$ResName,$ResLanguage = -1,$ModuleName = "") Local $DataType1 = "LONG",$DataType2 = "LONG" Local $LPVOID,$HRSRC,$ResSize,$HGLOBAL if IsString($ResName) Then $ResName = StringUpper($ResName) $DataType1 = "WSTR" EndIf If IsString($ResType) Then $ResType = StringUpper($ResType) $DataType2 = "WSTR" EndIf if StringLen($ModuleName) Then $HModule = _WinAPI_LoadLibraryEx($ModuleName,$LOAD_LIBRARY_AS_DATAFILE) if $HModule = 0 Then Return SetError(1,0,0) Else $HModule = 0 EndIf if ($ResLanguage <> -1) Then $HRSRC = DllCall("Kernel32.dll","ptr","FindResourceExW","ptr",$HModule, _ $DataType2,$ResType,$DataType1,$ResName,"WORD",$ResLanguage) if @error Or $HRSRC[0] = 0 Then Return SetError(2,0,0) Else $HRSRC = DllCall("Kernel32.dll","ptr","FindResourceW","ptr",$HModule, _ $DataType1,$ResName,$DataType2,$ResType) if @error Or $HRSRC[0] = 0 Then Return SetError(2,0,0) EndIf $HRSRC = $HRSRC[0] $ResSize = DllCall("Kernel32.dll","DWORD","SizeofResource","ptr",$HModule,"ptr",$HRSRC) if (@error Or $ResSize[0] = 0) Then Return SetError(3,0,0) $ResSize = $ResSize[0] $HGLOBAL = DllCall("Kernel32.dll","ptr","LoadResource","ptr",$HModule,"ptr",$HRSRC) if @error Or $HGLOBAL[0] = 0 Then Return SetError(4,0,0) $HGLOBAL = $HGLOBAL[0] $LPVOID = DllCall("Kernel32.dll","ptr","LockResource","ptr",$HGLOBAL) if @error Or $LPVOID[0] = 0 Then $BOOL = DllCall("Kernel32.dll","BOOL","FreeResource","ptr",$HGLOBAL) Return SetError(5,0,0) EndIf $LPVOID = $LPVOID[0] $ByteStruct = DllStructCreate("BYTE[" & $ResSize & "]") _MemMoveMemory($LPVOID,DllStructGetPtr($ByteStruct),$ResSize) $BOOL = DllCall("Kernel32.dll","BOOL","FreeResource","ptr",$HGLOBAL) if ($HModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(0,$ResSize,$ByteStruct) EndFunc Func ResToFile($FileName,$ResType,$ResName,$ResLanguage = -1,$ModuleName = "",$Mode = 10) $ByteStruct = ResGet($ResType,$ResName,$ResLanguage,$ModuleName) if @error Then Return SetError(1,0,False) $OpeFile = FileOpen($FileName,$Mode) if @error Then Return SetError(2,0,False) FileWrite($OpeFile,Binary(DllStructGetData($ByteStruct,1))) if @error Then Return SetError(3,0,False) FileClose($OpeFile) Return SetError(0,0,True) EndFunc Func StringResGet($ResType,$ResName,$ResLanguage = -1,$Unicode = False,$ModuleName = "") Local $DtatType = "CHAR" $ByteStruct = ResGet($ResType,$ResName,$ResLanguage,$ModuleName) if @error Then Return SetError(1,0,0) $ResSize = @extended $LPVOID = DllStructGetPtr($ByteStruct) if ($Unicode) Then $DtatType = "WCHAR" $ResSize = Int($ResSize/2) EndIf $StrStruct = DllStructCreate($DtatType & "[" & $ResSize & "]",$LPVOID) if @error Then Return SetError(2,0,0) $nString = DllStructGetData($StrStruct,1) Return SetError(0,StringLen($nString),$nString) EndFunc Func ResGetImage($ResType,$ResName,$ResLanguage = -1,$ModuleName = "") Switch $ResType Case $RT_BITMAP $hImage = LoadBitmap($ResName,$ModuleName) if @error Then Return SetError(1,0,0) Return SetError(0,1,$hImage) Case $RT_ICON $hImage = LoadIcon($ResName,$ModuleName) if @error Then Return SetError(2,0,0) Return SetError(0,3,$hImage) Case $RT_CURSOR $hImage = LoadCursor($ResName,$ModuleName) if @error Then Return SetError(3,0,0) Return SetError(0,5,$hImage) Case Else $ByteStruct = ResGet($ResType,$ResName,$ResLanguage,$ModuleName) if @error Then Return SetError(4,0,0) $ResSize = @extended $hMemory = _MemGlobalAlloc($ResSize,$GHND) if Not($hMemory) Then Return SetError(5,0,0) $hLock = _MemGlobalLock($hMemory) if Not($hLock) Then _MemGlobalFree($hMemory) Return SetError(6,0,0) EndIf _MemMoveMemory(DllStructGetPtr($ByteStruct),$hLock,$ResSize) $lpstream = CreateStreamOnHGlobal($hLock,True) if @error Then _MemGlobalFree($hMemory) Return SetError(7,0,0) EndIf $riid = _WinAPI_GUIDFromString("{7BF80981-BF32-101A-8BBB-00AA00300CAB}") if @error Then _MemGlobalFree($hMemory) Return SetError(8,0,0) EndIf $HRESULT = DllCall("OleAut32.dll","LONG","OleLoadPicture","PTR",$lpstream,"LONG", _ $ResSize,"BOOL",True,"ptr",DllStructGetPtr($riid),"idispatch*",0) if @error Or $HRESULT[0] <> 0 Then _MemGlobalFree($hMemory) Return SetError(9,0,0) EndIf $iPicture = $HRESULT[5] _MemGlobalFree($hMemory) Return SetError(0,Int($iPicture.Type()),Ptr($iPicture.Handle())) EndSwitch ;PICTYPE_UNINITIALIZED (-1) ;The picture object is currently uninitialized. This value is only valid as a return value ;from IPicture::get_Type and is not valid with the PICTDESC structure. ;PICTYPE_NONE = 0 ;A new picture object is to be created without an initialized state. This ;value is valid only in the PICTDESC structure. ;PICTYPE_BITMAP = 1 ;The picture type is a bitmap. When this value occurs in the PICTDESC structure, ;it means that the bmp field of that structure contains the relevant initialization parameters. ;PICTYPE_METAFILE = 2 ;The picture type is a metafile. When this value occurs in the PICTDESC structure, ;it means that the wmf field of that structure contains the relevant initialization parameters. ;PICTYPE_ICON = 3 ;The picture type is an icon. When this value occurs in the PICTDESC structure, ;it means that the icon field of that structure contains the relevant initialization parameters. ;PICTYPE_ENHMETAFILE = 4 ;The picture type is an enhanced metafile. When this value occurs in the PICTDESC structure, ;it means that the emf field of that structure contains the relevant initialization parameters. EndFunc Func LoadBitmap($lpBitmapName,$ModuleName = "") Local $DataType = "LONG" , $TestModule = StringLen($ModuleName) <> 0 if ($TestModule) Then $HModule = _WinAPI_LoadLibraryEx($ModuleName,$LOAD_LIBRARY_AS_DATAFILE) if $HModule = 0 Then Return SetError(1,0,0) Else $HModule = _WinAPI_GetModuleHandle(0) EndIf if IsString($lpBitmapName) Then $lpBitmapName = StringUpper($lpBitmapName) $DataType = "WSTR" EndIf $HBITMAP = DllCall("User32.dll","PTR","LoadBitmapW","PTR",$HModule,$DataType,$lpBitmapName) if @error Or $HBITMAP[0] = 0 Then if ($TestModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(2,0,0) EndIf if ($TestModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(0,0,$HBITMAP[0]) EndFunc Func LoadIcon($lpIconName,$ModuleName = "") Local $DataType = "LONG" , $TestModule = StringLen($ModuleName) <> 0 if ($TestModule) Then $HModule = _WinAPI_LoadLibraryEx($ModuleName,$LOAD_LIBRARY_AS_DATAFILE) if $HModule = 0 Then Return SetError(1,0,0) Else $HModule = _WinAPI_GetModuleHandle(0) EndIf if IsString($lpIconName) Then $lpIconName = StringUpper($lpIconName) $DataType = "WSTR" EndIf $HICON = DllCall("User32.dll","PTR","LoadIconW","PTR",$HModule,$DataType,$lpIconName) if @error Or $HICON[0] = 0 Then if ($TestModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(2,0,0) EndIf if ($TestModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(0,0,$HICON[0]) EndFunc Func LoadCursor($lpCursorName,$ModuleName = "") Local $DataType = "LONG" , $TestModule = StringLen($ModuleName) <> 0 if ($TestModule) Then $HModule = _WinAPI_LoadLibraryEx($ModuleName,$LOAD_LIBRARY_AS_DATAFILE) if $HModule = 0 Then Return SetError(1,0,0) Else $HModule = _WinAPI_GetModuleHandle(0) EndIf if IsString($lpCursorName) Then $lpCursorName = StringUpper($lpCursorName) $DataType = "WSTR" EndIf $HCURSOR= DllCall("User32.dll","PTR","LoadCursorW","PTR",$HModule,$DataType,$lpCursorName) if @error Or $HCURSOR[0] = 0 Then if ($TestModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(2,0,0) EndIf if ($TestModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(0,0,$HCURSOR[0]) EndFunc Func CreateStreamOnHGlobal($hGlobal,$fDeleteOnRelease) $WINOLE = DllCall("Ole32.dll","PTR","CreateStreamOnHGlobal","ptr", _ $hGlobal,"BOOL",$fDeleteOnRelease,"PTR*",0) if @error Or $WINOLE[0] <> 0 Then Return SetError(1,0,0) Return SetError(0,0,$WINOLE[3]) EndFunc