trung0407 Posted July 13, 2009 Share Posted July 13, 2009 Can someone gives me an example of the use of function Ptr() ? Is it like pointer in C++? Link to comment Share on other sites More sharing options...
bo8ster Posted July 13, 2009 Share Posted July 13, 2009 http://www.autoitscript.com/forum/index.php?showtopic=88214&st=0&p=642465&#entry642465 has it. Yes. Works the same way Int works for Integers. Handles are more common than pointers in AutoIt. When you need one you will know. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
herewasplato Posted July 13, 2009 Share Posted July 13, 2009 Can someone gives me an example of the use of function Ptr() ?Is it like pointer in C++?This is not exactly an example - but you can search the forum for Ptr and gets some other hits:http://www.autoitscript.com/forum/index.php?showtopic=72962&view=findpost&p=532163 [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
trancexx Posted July 13, 2009 Share Posted July 13, 2009 You use it when you want to convert some expression to pointer:ConsoleWrite("before: after:" & @CRLF) $iExpression = 129 $pExpression = Ptr($iExpression) ConsoleWrite($iExpression & " --> " & $pExpression & @CRLF)Why would you want to do that? Pointers are specific due to the difference on different systems (32bit-64bit). That is to say that if you are passing pointer to some function in form of integer it may not work. For example take WinSetState() function. It's working with pointer but not integer, though on 32bit systems it's almost the same thing.(Conditionality is important and to be taken into account when reading written above) ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
trung0407 Posted July 14, 2009 Author Share Posted July 14, 2009 So if I want to do this (in C): int a; int *b = &a; *b = 100; //a=100 How can I translate it in Autoit? Link to comment Share on other sites More sharing options...
trancexx Posted July 14, 2009 Share Posted July 14, 2009 Read about DllStruct functions. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
trung0407 Posted July 14, 2009 Author Share Posted July 14, 2009 Read about DllStruct functions.Well, that doesn't help and you didn't answer to my question Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted July 14, 2009 Share Posted July 14, 2009 Well, that doesn't help and you didn't answer to my question It would be something like: ;Example1 $Ex1A = DllStructCreate("int") $Ex1B = DllStructCreate("int", DllStructGetPtr($Ex1A)) DllStructSetData($Ex1B, 1, 100) ConsoleWrite(DllStructGetData($Ex1A, 1) & @CRLF) Now I have a better question for you, why do you want to do this? The only time this is needed in AutoIt is when working with Dll's, which should have lead you to this function already. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
trancexx Posted July 14, 2009 Share Posted July 14, 2009 It would be something like: The only time this is needed in AutoIt is when working with Dll's, which should have lead you to this function already. This is not entirely true. If it is I wouldn't be able to do this: expandcollapse popupOpt("MustDeclareVars", 1) Global $sFile = FileOpenDialog("Choose Bitmap", "", "Bitmap (*.bmp;*.dib)") If @error Then Exit ConsoleWrite($sFile & @CRLF) ConsoleWrite(_GetBMPInfo($sFile) & @CRLF) Func _GetBMPInfo($sFileBMP) Local $tBinary = DllStructCreate("byte[" & FileGetSize($sFileBMP) & "]") Local $hFile = FileOpen($sFileBMP, 16) DllStructSetData($tBinary, 1, FileRead($hFile)) FileClose($hFile) Local $tDIB = DllStructCreate("align 2;char Identifier[2];" & _ "dword BitmapSize;" & _ "short;" & _ "short;" & _ "dword BitmapOffset;" & _ "byte Body[" & DllStructGetSize($tBinary) - 14 & "]", _ DllStructGetPtr($tBinary)) If Not (DllStructGetData($tDIB, 1) == "BM") Then Return SetError(1, 0, "") ; Not BMP EndIf Local $tBitmap = DllStructCreate("dword HeaderSize", DllStructGetPtr($tDIB, "Body")) Local $iHeaderSize = DllStructGetData($tBitmap, "HeaderSize") Switch $iHeaderSize Case 40 $tBitmap = DllStructCreate("dword HeaderSize;" & _ "dword Width;" & _ "dword Height;" & _ "ushort Planes;" & _ "ushort BitPerPixel;" & _ "dword CompressionMethod;" & _ "dword Size;" & _ "dword Hresolution;" & _ "dword Vresolution;" & _ "dword Size;" & _ "dword ImportantColors;", _ DllStructGetPtr($tDIB, "Body")) Case 12 $tBitmap = DllStructCreate("dword HeaderSize;" & _ "ushort Width;" & _ "ushort Height;" & _ "ushort Planes;" & _ "ushort BitPerPixel;", _ DllStructGetPtr($tDIB, "Body")) Case Else Return SetError(2, 0, "") ; some old format EndSwitch Local $iWidth = DllStructGetData($tBitmap, "Width") Local $iHeight = DllStructGetData($tBitmap, "Height") Local $iCompressionMethod = DllStructGetData($tBitmap, "CompressionMethod") Local $sCompressionMethod Switch $iCompressionMethod Case 0 $sCompressionMethod = "None" Case 1 $sCompressionMethod = "RLE 8-bit/pixel" Case 2 $sCompressionMethod = "RLE 4-bit/pixel" Case 3 $sCompressionMethod = "Bit field" Case 4 $sCompressionMethod = "JPEG" Case 5 $sCompressionMethod = "PNG" EndSwitch Local $sCollected = " Width: " & $iWidth & @LF & _ " Height: " & $iHeight & @LF & _ " Planes: " & DllStructGetData($tBitmap, "Planes") & @LF & _ " BitPerPixel: " & DllStructGetData($tBitmap, "BitPerPixel") & @LF & _ " Compression Method: " & $sCompressionMethod Local $iRawBitmapSize = DllStructGetData($tBitmap, "Size") If $iRawBitmapSize Then $sCollected &= @LF & " Raw bitmap data size: " & $iRawBitmapSize & " bytes" EndIf Return SetError(0, 0, $sCollected) EndFunc ;==>_GetBMPInfo Choose some bitmap file to get basic info out of it. Btw, that code is taken from here. @trung0407, don't be impatient. Are you expecting to comprehend all after reading it once? You were given the answer. And if you wanted code then you only needed to ask. But see how great here is. Your thoughts were read after all. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now