Sign in to follow this  
Followers 0
komalo

DllStructCreate and unknown Data Type

18 posts in this topic

#1 ·  Posted (edited)

i am trying to create a struct of LPCREATESTRUCT and HWND types

but i always get @error = 2

because they are unknown Data Type

Creates a C/C++ style structure to be used in DllCall.

DllStructCreate ( "Struct" [,Pointer] )

Parameters

"Struct" A string representing the structure to create (See Remarks).

Pointer If supplied the struct will not allocate memory but use the pointer supplied.

Return Value

Success: A variable for use with DllStruct calls.

Failure: 0.

@Error: 0 = No Error.

1 = Variable passed to DllStructCreate was not a string.

2 = There is an unknown Data Type in the string passed.

3 = Failed to allocate the memory needed for the struct, or Pointer = 0.

4 = Error allocating memory for the passed string.

is there's a solution for this problem ? Edited by komalo

[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites



Post your code. I personally have no idea what you need to do until I see the code, but the type is not the same as C++. You need to read the helpfile and look a DllCall.

Share this post


Link to post
Share on other sites

as an example

$Struct = DllStructCreate("LPCREATESTRUCT lpcs;HWND hwndInsertAfter;")
MsgBox("","",$Struct & " " & @error )
$Struct = 0

the problem is when i try to create the struct , it is not created and @error set to 2 which is

@Error: 0 = No Error.

1 = Variable passed to DllStructCreate was not a string.

2 = There is an unknown Data Type in the string passed.

3 = Failed to allocate the memory needed for the struct, or Pointer = 0.

4 = Error allocating memory for the passed string.


[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites

komalo

LPCREATESTRUCT is not a valid type. Read the DllCall description in the help file.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

no you don't understand

LPCREATESTRUCT is a user-defined type but it is no defined in autoit

see : http://msdn.microsoft.com/en-us/library/ms644962(VS.85).aspx

Edited by komalo

[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites

komalo

$CBT_CREATEWND = DllStructCreate("ptr lpcs;hwnd hwndInsertAfter")

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

no i can't use that , the data types must be identical like in this struct

because i am using it with a pointer to this struct

so using ptr type doesn't solve the problem

Edited by komalo

[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites

no i can't use that , the data types must be identical like in this struct

because i am using it with a pointer to this struct

so using ptr type doesn't solve the problem

Don't be silly.

If I take a cow to France it becomes une vache, but the cow itself hasn't changed has it?

Since the data types are identical it's very difficult to understand your problem. The link you gave to the struct states the the first element is a pointer. So in AutoIt that's called "ptr".

The only thing you have to worry about is if you are working in a 64 bit OS and then you can use "long_ptr" which ensures that it is the correct size, but your link was for WIn32 so that seems unlikely to be needed.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

i told you that because i tried using "ptr" and "long_ptr' Before

and then it create it and i can use DllStructGetPtr

but when using DllStructGetData an error happens

so my guess that i have to use the same types


[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

that's okay , i gave up with this struct and found

another way for my script , thank you all .


[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Well, I have the solution now. Structures in structures are just inserted in place of the name:

Global Const $tagCREATESTRUCT = "ptr lpCreateParams;hwnd hInstance;hwnd hMenu; HWND hwndParent; int cy; int cx; int y; int x; LONG style; ptr lpszName; ptr lpszClass; DWORD dwExStyle"
; lpCreateParams is a lpvoid
; lpszName is a pointer to a string ( LPCTSTR )
; lpszClass is a pointer to a string ( LPCTSTR )

Global Const $tagCBT_CREATEWND = $tagCREATESTRUCT & ";hwnd hwndInsertAfter"

$CBT_CREATEWND = DllStructCreate($tagCBT_CREATEWND)
MsgBox("","",$CBT_CREATEWND & " " & @error )
$CBT_CREATEWND = 0
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

well your seems code seems write

but my problem continues on DllStructGetData

i am using setwindowshook in my code , one of the messages

of it is $HCBT_CREATEWND which returns a pointer to CBT_CREATEWND struct

in the LParam , i want to get the data in that structure , so i

used DllStructCreate with LParam as the pointer parameter

and get the data DllStructGetData but it always returns

an error (the memory couldn't be "read" ) on DllStructGetData

Edited by komalo

[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites

and here's the code of callback function

$CBT_CREATEWND = DllStructCreate("LPCREATESTRUCT lpcs;HWND hwndInsertAfter;",$LParam)

FileWriteLine("NewWinLog.txt", DllStructGetData($CBT_CREATEWND, 1))


[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites

ProgAndy

Structures in structures are just inserted in place of the name

Hi! You think your solution correct? But I think this type should be a pointer(ptr) to a CREATESTRUCT structure. Your solution right for this example, see a hdr type. :P

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Hmm, this works?

CODE
#include <WinAPI.au3>

Const $HCBT_CREATEWND = 3

Global Const $tagCREATESTRUCT = "ptr lpCreateParams;hwnd hInstance;hwnd hMenu; HWND hwndParent; int cy; int cx; int y; int x; LONG style; ptr lpszName; ptr lpszClass; DWORD dwExStyle"

; lpCreateParams is a lpvoid

; lpszName is a pointer to a string ( LPCTSTR )

; lpszClass is a pointer to a string ( LPCTSTR )

Global Const $tagCBT_CREATEWND = "ptr lpcs;hwnd hwndInsertAfter"

$ShellCallb = DllCallbackRegister("CBTProc","long_ptr","int;wparam;lparam")

$HookHwnd = _WinAPI_SetWindowsHookEx($WH_CBT,DllCallbackGetPtr($ShellCallb),0,_WinAPI_GetCurrentThreadId())

MsgBox(0, '', $HookHwnd)

While 1

Sleep(1000)

WEnd

Func OnAutoItExit()

_WinAPI_UnhookWindowsHookEx($HookHwnd)

EndFunc

Func CBTProc($nCode,$wParam,$lParam)

;~ int nCode,

;~ WPARAM wParam,

;~ LPARAM lParam

If $nCode = $HCBT_CREATEWND Then

$CBT_CREATEWND = DllStructCreate($tagCBT_CREATEWND,$lParam)

$CREATESTRUCT = DllStructCreate($tagCREATESTRUCT,DllStructGetData($CBT_CREATEWND,1))

ConsoleWrite(DllStructGetData($CREATESTRUCT,"y") & @CRLF)

EndIf

_WinAPI_CallNextHookEx($WH_CBT,$nCode,$wParam,$lParam)

EndFunc

//Edit: You are right. The values are strange ... I changed to the ptr solution and it works. Thx

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

i am still getting the problem with my script but not yours

well it seems that the problem that i a am using it with Larry's hook.dll

i really don't get it why it doesn't work , i don't want to post my code so

i will work with the the other


[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

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