Sign in to follow this  
Followers 0
Homes32

[Solved] Dll call writing data to struct.

7 posts in this topic

#1 ·  Posted (edited)

hello all,

I'm working on trying to get Attributes from a .wim file and have hit a wall.

calling the WIMGetAttributes function from wimgapi.dll always returns false for me and GetLastError() returns 87 ERROR_INVALID_PARAMETER

as far as I can tell I have all the parameters correct. and I can confirm that I get the correct handle for $hWim and that the struct is created successfully with a size of: 552

I've been looking at this for so long its hard for me to tell if I have something screwed up. has anybody had success calling this function with autoit?

please let me know if there is any information I forgot to give.

thanks.

Homes32

Func _WIM_GetImageAttributes($hWim)

    Local $aReturn[2] ; array to hold the return data

    Local $hWimInfo = DllStructCreate($tagWIM_INFO)
    if @error Then MsgBox(0,"","Error in DllStructCreate: " & @error);

    $aReturn[0] = DllCall($ghwimgapi, "int", "WIMGetAttributes", _
        "ptr", $hWim, _
        "ptr", DllStructGetPtr($hWimInfo), _
        "int", DllStructGetSize($hWimInfo))
    If @error Then Return SetError(@error, @extended, $aReturn)

    ;$aReturn[0] = DllCall return value


    Return SetError(@error, _WinAPI_GetLastError(), $aReturn[0])
EndFunc   ;==>_WIM_GetAttributes

Global Const $tagWIM_INFO = "wchar WimPath[256];byte Guid[16];dword ImageCount;dword CompressionType;ushort PartNumber;" & _
                         "ushort TotalParts;dword BootIndex;dword WimAttributes;dword WimFlagsAndAttr"
[/autoit]

function prototype and struct definition

BOOL
WINAPI
WIMGetAttributes(
    IN  HANDLE     hWim,
    OUT LPWIM_INFO lpWimInfo,
    IN  DWORD      cbWimInfo
    );

typedef struct _WIM_INFO
{
    WCHAR  WimPath[MAX_PATH];
    GUID   Guid;
    DWORD  ImageCount;
    DWORD  CompressionType;
    USHORT PartNumber;
    USHORT TotalParts;
    DWORD  BootIndex;
    DWORD  WimAttributes;
}
WIM_INFO, *PWIM_INFO, *LPWIM_INFO;
Edited by Homes32

Share this post


Link to post
Share on other sites



I'm far from dllcall expert, but some things look wrong here, comments.

Func _WIM_GetImageAttributes($hWim)

    Local $aReturn[2] ; array to hold the return data

    Local $hWimInfo = DllStructCreate($tagWIM_INFO)
    if @error Then MsgBox(0,"","Error in DllStructCreate: " & @error);

    $aReturn[0] = DllCall($ghwimgapi, "int", "WIMGetAttributes", _
        "ptr", $hWim, _
        "ptr", DllStructGetPtr($hWimInfo), _
        "int", DllStructGetSize($hWimInfo))
    If @error Then Return SetError(@error, @extended, $aReturn);<---- not certain you can return and array of array from seterror

    ;$aReturn[0] = DllCall return value  <--- $aReturn[0] will hold another array, if you look at helpfile dllcall returns an array.


    Return SetError(@error, _WinAPI_GetLastError(), $aReturn[0]) 
EndFunc   ;==>_WIM_GetAttributes

Global Const $tagWIM_INFO = "wchar WimPath[256];byte Guid[16];dword ImageCount;dword CompressionType;ushort PartNumber;" & _
                         "ushort TotalParts;dword BootIndex;dword WimAttributes;dword WimFlagsAndAttr"

Func _WIM_GetImageAttributes($hWim)

    Local $aReturn ; array to hold the return data

    Local $hWimInfo = DllStructCreate($tagWIM_INFO)
    if @error Then MsgBox(0,"","Error in DllStructCreate: " & @error);

    $aReturn = DllCall($ghwimgapi, "int", "WIMGetAttributes", _
        "ptr", $hWim, _
        "ptr", DllStructGetPtr($hWimInfo), _
        "int", DllStructGetSize($hWimInfo))
    If @error Then Return SetError(@error, @extended, $aReturn)

      Return SetError(@error, _WinAPI_GetLastError(), $aReturn[0]) ; might now hold your return value
EndFunc   ;==>_WIM_GetAttributes

Global Const $tagWIM_INFO = "wchar WimPath[256];byte Guid[16];dword ImageCount;dword CompressionType;ushort PartNumber;" & _
                         "ushort TotalParts;dword BootIndex;dword WimAttributes;dword WimFlagsAndAttr"

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Sorry, you say you have error with param

How about

$aReturn[0] = DllCall($ghwimgapi, "int", "WIMGetAttributes", _
        "HWND", $hWim, _
        "ptr", DllStructGetPtr($hWimInfo), _
        "DWORD", DllStructGetSize($hWimInfo))

Edit:

Maybe change int return type to BOOLEAN or BYTE

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Try this:

Global Const $tagWIM_INFO = "wchar WimPath[256];byte Guid[16];dword ImageCount;dword CompressionType;ushort PartNumber;ushort TotalParts;dword BootIndex;dword WimAttributes;dword WimFlagsAndAttr"

Func _WIM_GetImageAttributes( $hWim )
    Local $hWimInfo = DllStructCreate( $tagWIM_INFO )

    If @error Then
        MsgBox( 0 , "" , "Error in DllStructCreate: " & @error )
    EndIf

    Local $aReturn = DllCall( $ghwimgapi, "bool", "WIMGetAttributes", _
        "handle" , $hWim, _
        "ptr"   , DllStructGetPtr( $hWimInfo), _
        "dword"  , DllStructGetSize( $hWimInfo ) )

    If @error Then
        Return SetError( @error , @extended , $aReturn )
    EndIf

    Return SetError( @error , _WinAPI_GetLastError() , $aReturn[0] )
EndFunc

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

thanks for the replys.

I took out the array stuff but that and changing the data type makes no difference. (I tried before posting and tried your examples again just to be sure.)

any other thoughts?

Func _WIM_GetImageAttributes($hWim)

    Local $pWimInfo = DllStructCreate($tagWIM_INFO)
    if @error Then MsgBox(0,"","Error in DllStructCreate: " & @error);

    $aReturn = DllCall($ghwimgapi, "bool", "WIMGetAttributes", _
        "handle", $hWim, _
        "ptr", DllStructGetPtr($pWimInfo), _
        "dword", DllStructGetSize($pWimInfo))
    If @error Then Return SetError(@error, @extended, $aReturn)

    Return SetError(@error, _WinAPI_GetLastError(), $aReturn[0])
EndFunc   ;==>_WIM_GetAttributes
Edited by Homes32

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

MAX_PATH is 260.

edit:

That means you are not providing enough free writing space and that's why it's failing

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

MAX_PATH is 260.

edit:

That means you are not providing enough free writing space and that's why it's failing

that was my problem! thanks for pointing it out! :)

Cheers!

Homes32

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0