DllCall und Pointer

  • Ich hab ein Problem mit Pointern, ich erstelle eine DLLStruct und gebe den Pointer davon an DllCall, die Variable wird aber nicht verändert, nichtmal ein Hilfebeispiel mit soetwas funktioniert.

    Mein Script:

    Spoiler anzeigen
    [autoit]


    #include <DLLshow.au3>
    #include <GDIPlus.au3>
    $gui="";GUICreate("")
    ;~ ;GUISetState()
    $datei="C:\Windows\system32\shell32.dll"
    $x=_PickIcon($gui,$datei)
    MsgBox(0,@error,$x) ;$x ist immer 0 ..
    $icon=DllStructCreate("int ico")
    $picon=DllStructGetPtr("ico")
    _WinAPI_ExtractIconEx($datei,$x,$picon,0,1)
    $hico=DllStructGetData($icon,"ico")
    _GDIPlus_Startup()
    $x=_GDIPlus_BitmapCreateFromHBITMAP($hico)
    _gdiplus_imageshow($x)
    _WinAPI_DestroyIcon($hico)
    _GDIPlus_BitmapDispose($x)
    _GDIPlus_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    Func _PickIcon($hwnd,$pfad="")
    Local $int=DllStructCreate("int index")
    Local $pint=DllStructGetPtr($int)
    Local $ret=DllCall("shell32.dll","int","PickIconDlg","hwnd",$hwnd,"wstr",$pfad,"uint",999,"int*",$pint)
    If @error>0 Then Return -1
    Local $index=DllStructGetData($int,"index")
    If $ret[0]=0 Then $index=0
    Return $index
    EndFunc

    [/autoit]

    DLLshow.au3:

    Spoiler anzeigen
    [autoit]


    #include-once
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_ImageLoadFromLibrary($dll, $resname)
    $memdll = _WinAPI_LoadLibrary($dll)
    $hbitmap = _WinAPI_LoadBitmap($memdll, $resname)
    $img = _GDIPlus_BitmapCreateFromHBITMAP($hbitmap)
    _WinAPI_FreeLibrary($memdll)
    _WinAPI_DeleteObject($hbitmap)
    Return $img
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_ImageShow($img,$titel="",$x=-1,$y=-1)
    If $img=0 Then Return -1
    Local $wx,$wy
    If $x=-1 or $x>@DesktopWidth-50 Then
    $x=_GDIPlus_ImageGetWidth($img)
    if $x>@DesktopWidth-50 Then $x=@DesktopWidth-50
    EndIf
    If $y=-1 or $y>@DesktopWidth-50 Then
    $y=_GDIPlus_ImageGetHeight($img)
    if $y>@DesktopWidth-50 Then $y=@DesktopWidth-50
    EndIf
    $wx=$x
    $wy=$y
    Local $gui=GUICreate($titel,$x,$y,Default,Default,BitOR(0x00C00000,0x00080000)) ;bitor($WS_CAPTION,$WS_SYSMENU)
    GUISetState(@SW_SHOW,$gui)
    Local $gra=_GDIPlus_GraphicsCreateFromHWND($gui)
    Local $buffer=_GDIPlus_BitmapCreateFromGraphics($wx,$wy,$gra)
    Local $backgra=_GDIPlus_ImageGetGraphicsContext($buffer)
    _GDIPlus_GraphicsSetSmoothingMode($backgra,2)
    _GDIPlus_GraphicsClear($backgra)
    _GDIPlus_GraphicsDrawImageRect($backgra,$img,0,0,$wx,$wy)
    While GUIGetMsg()<>-3 ;$GUI_EVENT_CLOSE
    _WinAPI_RedrawWindow($gui, "", "", 1280) ;$RDW_UPDATENOW + $RDW_FRAME
    _GDIPlus_GraphicsDrawImageRect($gra,$buffer,0,0,$wx,$wy)
    Sleep(10)
    WEnd
    _GDIPlus_GraphicsDispose($backgra)
    _GDIPlus_BitmapDispose($buffer)
    _GDIPlus_GraphicsDispose($gra)
    GUIDelete($gui)
    Return 1
    EndFunc

    [/autoit]

    Hilfebeispiel:

    Spoiler anzeigen
    [autoit]


    #AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
    #include <GuiConstantsEx.au3>
    #include <WinAPI.au3>
    #include <GuiListView.au3>
    #include <GuiImageList.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    _Main()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Main()
    Local $listview, $hImage
    Local $Wow64 = ""
    If @AutoItX64 Then $Wow64 = "\Wow6432Node"
    Local $AutoItDir = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $Wow64 & "\AutoIt v3\AutoIt", "InstallDir")

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("ImageList AddIcon", 410, 300)
    $listview = GUICtrlCreateListView("", 2, 2, 404, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    ; Create an image list with images
    $hImage = _GUIImageList_Create(11, 11)
    AddIcon($hImage, $AutoItDir & "\Icons\filetype1.ico")
    AddIcon($hImage, $AutoItDir & "\Icons\filetype2.ico")
    AddIcon($hImage, $AutoItDir & "\Icons\filetype3.ico")
    _GUICtrlListView_SetImageList($listview, $hImage, 1)

    [/autoit] [autoit][/autoit] [autoit]

    ; Add columns
    _GUICtrlListView_AddColumn($listview, "Column 1", 100, 0, 0)
    _GUICtrlListView_AddColumn($listview, "Column 2", 100, 1, 1)
    _GUICtrlListView_AddColumn($listview, "Column 3", 100, 2, 2)
    _GUICtrlListView_AddColumn($listview, "Column 4", 100)

    [/autoit] [autoit][/autoit] [autoit]

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    EndFunc ;==>_Main

    [/autoit] [autoit][/autoit] [autoit]

    ; This is the long way to add an icon. Use _GUIImageList_AddIcon instead
    Func AddIcon($hWnd, $sFile, $iIndex = 0)
    Local $pIcon, $tIcon, $hIcon

    [/autoit] [autoit][/autoit] [autoit]

    $tIcon = DllStructCreate("int Icon")
    $pIcon = DllStructGetPtr($tIcon)
    _WinAPI_ExtractIconEx($sFile, $iIndex, 0, $pIcon, 1)
    $hIcon = DllStructGetData($tIcon, "Icon")
    _GUIImageList_ReplaceIcon($hWnd, -1, $hIcon)
    _WinAPI_DestroyIcon($hIcon)
    EndFunc ;==>AddIcon

    [/autoit]

    Wär nett, wenn mir jemand helfen könnte ^^

    Einmal editiert, zuletzt von TheShadowAE (17. April 2010 um 13:08)

  • ExtractIconEx erstellt ein HICON und keine HBITMAP. Daher funktioniert die Zeile nicht:
    $x=_GDIPlus_BitmapCreateFromHBITMAP($hico)

  • Jep, du hast hier eine doppelte Referenz verwendet. int* ist schon ein Pointer auf einen Integer und du setzt dann noch eine DLLStruct rein. So läuft alles:

    Spoiler anzeigen
    [autoit]

    #include-once
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_ImageLoadFromLibrary($dll, $resname)
    $memdll = _WinAPI_LoadLibrary($dll)
    $hbitmap = _WinAPI_LoadBitmap($memdll, $resname)
    $img = _GDIPlus_BitmapCreateFromHBITMAP($hbitmap)
    _WinAPI_FreeLibrary($memdll)
    _WinAPI_DeleteObject($hbitmap)
    Return $img
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_ImageShow($img,$titel="",$x=-1,$y=-1)
    If $img=0 Then Return -1
    Local $wx,$wy
    If $x=-1 or $x>@DesktopWidth-50 Then
    $x=_GDIPlus_ImageGetWidth($img)
    if $x>@DesktopWidth-50 Then $x=@DesktopWidth-50
    EndIf
    If $y=-1 or $y>@DesktopWidth-50 Then
    $y=_GDIPlus_ImageGetHeight($img)
    if $y>@DesktopWidth-50 Then $y=@DesktopWidth-50
    EndIf
    $wx=$x
    $wy=$y
    Local $gui=GUICreate($titel,$x,$y,Default,Default,BitOR(0x00C00000,0x00080000)) ;bitor($WS_CAPTION,$WS_SYSMENU)
    GUISetState(@SW_SHOW,$gui)
    Local $gra=_GDIPlus_GraphicsCreateFromHWND($gui)
    Local $buffer=_GDIPlus_BitmapCreateFromGraphics($wx,$wy,$gra)
    Local $backgra=_GDIPlus_ImageGetGraphicsContext($buffer)
    _GDIPlus_GraphicsSetSmoothingMode($backgra,2)
    _GDIPlus_GraphicsClear($backgra)
    _GDIPlus_GraphicsDrawImageRect($backgra,$img,0,0,$wx,$wy)
    While GUIGetMsg()<>-3 ;$GUI_EVENT_CLOSE
    _WinAPI_RedrawWindow($gui, "", "", 1280) ;$RDW_UPDATENOW + $RDW_FRAME
    _GDIPlus_GraphicsDrawImageRect($gra,$buffer,0,0,$wx,$wy)
    Sleep(10)
    WEnd
    _GDIPlus_GraphicsDispose($backgra)
    _GDIPlus_BitmapDispose($buffer)
    _GDIPlus_GraphicsDispose($gra)
    GUIDelete($gui)
    Return 1
    EndFunc
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $x=_PickIcon(0)
    If @error Then Exit
    MsgBox(0,$x[0],$x[1])

    [/autoit] [autoit][/autoit] [autoit]

    $icon=DllStructCreate("ptr")
    $picon=DllStructGetPtr($icon)
    _WinAPI_ExtractIconEx($x[0],$x[1],$picon,0,1)
    $hico=DllStructGetData($icon,1)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    $x=_GDIPlus_BitmapCreateFromHICON($hico)
    _gdiplus_imageshow($x)
    _WinAPI_DestroyIcon($hico)
    _GDIPlus_BitmapDispose($x)
    _GDIPlus_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    Func _PickIcon($hwnd,$pfad="")
    Local $ret=DllCall("shell32.dll","int","PickIconDlg","hwnd",$hwnd,"wstr",$pfad,"uint",999,"int*",0)
    If @error Or $ret[0]=0 Then SetError(1,0,0)
    Local $aResult[2] = [$ret[2], $ret[4]]
    Return $aResult
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_BitmapCreateFromHICON($hIcon)
    ; Author: ProgAndy
    Local $aResult = DllCall($ghGDIPdll, "int", "GdipCreateBitmapFromHICON", "ptr", $hIcon, "ptr*", 0)
    If @error Then Return SetError(1,0,0)
    Return SetError($aResult[0], 0, $aResult[2])
    EndFunc

    [/autoit]