Jump to content

Pointer?


Recommended Posts

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

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

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

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.

Link to comment
Share on other sites

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:

Opt("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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...