Jump to content

Using DLL Functions - AU3_ClipGet


MITH
 Share

Go to solution Solved by funkey,

Recommended Posts

I am writing a code in Excel (VBA) to get the Clipboard contents using the Autoit DLL. But I am not able to get it work. It is giving wrong Output.

Here is my code:

Public Declare Sub AU3_ClipGet Lib "C:\Windows\System32\AutoItX3.dll" (ByVal szClip As LongPtr, ByVal nBufSize As Integer)

Sub Autoit_ClipGet()
Dim ClipPtr As LongPtr, ClipContents As String, StrClip As String
StrClip = ""
ClipPtr = StrPtr(StrClip)
AU3_ClipGet ClipPtr, Len(ClipPtr)
MsgBox ClipPtr
End Sub

Am I missing something? Not Sure.

Expecting some expert advice to get this work. Please help.

Thanks in advance for help.

 

Link to comment
Share on other sites

  • Solution

I did not test the AU3_DLL with excel, but you could get the clipboard contents this way: http://excel-macro.tutorialhorizon.com/vba-excel-get-text-from-the-windows-clipboard/

Edit: Tried both versions with success:

Const DATAOBJECT_BINDING As String = "new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"
Public Declare Sub AU3_ClipGet Lib "C:\Program Files (x86)\AutoIt3\AutoItX\AutoItX3.dll" (ByVal szClip As Long, ByVal nBufSize As Integer)


Public Function PasteFromClipboard() As String
    On Error GoTo Whoa

    With CreateObject(DATAOBJECT_BINDING)
        .GetFromClipboard
        PasteFromClipboard = .GetText
    End With
    Exit Function
    
Whoa:
   'If Err <> 0 Then MsgBox "Data on clipboard is not text or is empty"
   'PasteFromClipboard = ""
End Function
 
Public Sub ShowTextFromClipBoard()
    If (CountClipboardFormats() = 0) = True Then
        MsgBox "Clipboard is empty"
    Else
        MsgBox PasteFromClipboard()
    End If
End Sub

Sub Autoit_ClipGet()
    Dim StrClip As String
    StrClip = Space(2048)
    AU3_ClipGet StrPtr(StrClip), 2048
    MsgBox StrClip
End Sub
Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

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...