Skip to main content

Hi,

I want to use user32.dll in acucobol, but only for the GetClipboardData function.

I tired this but it doesn't return anything:

      

           call    user32.dll@WINAPI ON EXCEPTION DISPLAY "err start".

           CALL    "GetClipboardData" USING

                   by REFERENCE DATA-LINK

                   BY               VALUE BUF-SIZE

                   ON EXCEPTION DISPLAY "err call".

 

           DISPLAY DATA-LINK        AT 0101 ERASE EOL.

           display "end"         AT 1001 ERASE EOL.

           ACCEPT  k at 2480.

           CANCEL  "user32".

currently using clipacu.dll but that only supports win 32 bit

Thanks,

Bart Pelgrims


#user32.dll
#AcuCobol

Hi,

I want to use user32.dll in acucobol, but only for the GetClipboardData function.

I tired this but it doesn't return anything:

      

           call    user32.dll@WINAPI ON EXCEPTION DISPLAY "err start".

           CALL    "GetClipboardData" USING

                   by REFERENCE DATA-LINK

                   BY               VALUE BUF-SIZE

                   ON EXCEPTION DISPLAY "err call".

 

           DISPLAY DATA-LINK        AT 0101 ERASE EOL.

           display "end"         AT 1001 ERASE EOL.

           ACCEPT  k at 2480.

           CANCEL  "user32".

currently using clipacu.dll but that only supports win 32 bit

Thanks,

Bart Pelgrims


#user32.dll
#AcuCobol

I don't recognize the   user32.dll@WINAPI syntax  As long as user32.dll in in the PATH or other environment variables that the Acu runtime uses, call "user32" should work.   www.microfocus.com/.../BKITITWINDS012.html


I don't recognize the   user32.dll@WINAPI syntax  As long as user32.dll in in the PATH or other environment variables that the Acu runtime uses, call "user32" should work.   www.microfocus.com/.../BKITITWINDS012.html

I just need a small example how to call this dll, clearly I'm doing something wrong here. This code doesn't give an error, but it neither returns the clipboard data.


I just need a small example how to call this dll, clearly I'm doing something wrong here. This code doesn't give an error, but it neither returns the clipboard data.

ftp35@amerftp.microfocus.com/.../clipacu.zip  This is an older example which uses a dll called clipacu.dll. I hope this helps.


ftp35@amerftp.microfocus.com/.../clipacu.zip  This is an older example which uses a dll called clipacu.dll. I hope this helps.

That is the thing we need to replace as clipacu.dll doesn't work on 64-bit.... (and the link doesn't seem to work)


ftp35@amerftp.microfocus.com/.../clipacu.zip  This is an older example which uses a dll called clipacu.dll. I hope this helps.

Based on the code you were using, I didn't see that you actually sent any data to the clipboard. This seems to work for me: 

STRING "This is a sample transmission to clipboard"
LOW-VALUES DELIMITED BY SIZE INTO DATA-LINK.
call "user32.dll@WINAPI" ON EXCEPTION DISPLAY "err start".

Typically, there is a Set and Get function. I would use the Set - to send data, then use a different COBOL data item and use Get to see if you receive the data you've placed on the clipboard


Based on the code you were using, I didn't see that you actually sent any data to the clipboard. This seems to work for me: 

STRING "This is a sample transmission to clipboard"
LOW-VALUES DELIMITED BY SIZE INTO DATA-LINK.
call "user32.dll@WINAPI" ON EXCEPTION DISPLAY "err start".

Typically, there is a Set and Get function. I would use the Set - to send data, then use a different COBOL data item and use Get to see if you receive the data you've placed on the clipboard

This code is incomplete, I actually need the call "GetClipboardData" to do the actual call. The ones I tried don't do anything.

Something like this (but this code doesn't do anything)

CALL "SetClipboardData" USING BY REFERENCE DATA-LINK

BY VALUE BUF-SIZE

Or something like that.


This code is incomplete, I actually need the call "GetClipboardData" to do the actual call. The ones I tried don't do anything.

Something like this (but this code doesn't do anything)

CALL "SetClipboardData" USING BY REFERENCE DATA-LINK

BY VALUE BUF-SIZE

Or something like that.

Yes, the user32 functions are quite different from the clipacu example. I don't have a working example, but I noticed that user32 and clipboard functions on the internet shows that OpenClipboard needs to be called. call "user32"  then call "OpenClipboard" giving my-handle.  The SetClipboardData and other functions use handles. 


Yes, the user32 functions are quite different from the clipacu example. I don't have a working example, but I noticed that user32 and clipboard functions on the internet shows that OpenClipboard needs to be called. call "user32"  then call "OpenClipboard" giving my-handle.  The SetClipboardData and other functions use handles. 

Too bad there isn't even an example on how to use handles/user32.dll in the manual...


Too bad there isn't even an example on how to use handles/user32.dll in the manual...

The examples I've seen seem to include calls to kernel32, it appear you need to provide memory space for using the clipboard. I'm not sure how best to test this, as I don't know if placing data on the clipboard makes that data to other processes / applications.

id division.
program-id. testclip.
special-names.

working-storage section.
78 GMEM-MOVEABLE value 2.
78 CF-TEXT value 1.
01 hWndNewOwner pic x(4) comp-5 value zeroes.
01 retCode pic x(4) comp-5 value zeroes.
01 any-key pic x.
01 myHandle pointer.
01 myPointer pointer.
linkage section.
01 datatocopy pic x(30).
procedure division.
call "kernel32".
call "user32".

call "GlobalAlloc"
using by value GMEM-MOVEABLE
by value length of datatocopy
returning myHandle
end-call
call "GlobalLock"
using by value myHandle
returning myPointer
end-call
set address of datatocopy to myPointer
STRING "This is a sample transmission to clipboard"
LOW-VALUES DELIMITED BY SIZE INTO
datatocopy
call "GetActiveWindow"
returning hWndNewOwner
end-call

call "OpenClipboard"
using by value hWndNewOwner
returning retCode
end-call
if retCode = 0
display "error"
else
call "EmptyClipboard"
call "SetClipboardData"
using by value CF-TEXT
by reference datatocopy
end-call
call "CloseClipboard"
end-if
call "GlobalUnlock"
using by value myHandle
returning retCode
end-call
call "GlobalFree" using by value myHandle
cancel "user32".
cancel "kernel32".
stop run.


The examples I've seen seem to include calls to kernel32, it appear you need to provide memory space for using the clipboard. I'm not sure how best to test this, as I don't know if placing data on the clipboard makes that data to other processes / applications.

id division.
program-id. testclip.
special-names.

working-storage section.
78 GMEM-MOVEABLE value 2.
78 CF-TEXT value 1.
01 hWndNewOwner pic x(4) comp-5 value zeroes.
01 retCode pic x(4) comp-5 value zeroes.
01 any-key pic x.
01 myHandle pointer.
01 myPointer pointer.
linkage section.
01 datatocopy pic x(30).
procedure division.
call "kernel32".
call "user32".

call "GlobalAlloc"
using by value GMEM-MOVEABLE
by value length of datatocopy
returning myHandle
end-call
call "GlobalLock"
using by value myHandle
returning myPointer
end-call
set address of datatocopy to myPointer
STRING "This is a sample transmission to clipboard"
LOW-VALUES DELIMITED BY SIZE INTO
datatocopy
call "GetActiveWindow"
returning hWndNewOwner
end-call

call "OpenClipboard"
using by value hWndNewOwner
returning retCode
end-call
if retCode = 0
display "error"
else
call "EmptyClipboard"
call "SetClipboardData"
using by value CF-TEXT
by reference datatocopy
end-call
call "CloseClipboard"
end-if
call "GlobalUnlock"
using by value myHandle
returning retCode
end-call
call "GlobalFree" using by value myHandle
cancel "user32".
cancel "kernel32".
stop run.

This is great, and it works, but I'm looking for the GetClipboardData, not the Set. I tried to adapt it to do this, but so far failed to do so. If you have an example to do that it would be great.


This is great, and it works, but I'm looking for the GetClipboardData, not the Set. I tried to adapt it to do this, but so far failed to do so. If you have an example to do that it would be great.

If someone is looking for this, I found the solution for using GetClipboardData with AcuCobol:

       IDENTIFICATION DIVISION.
       program-id.   testclip.
       ENVIRONMENT DIVISION.

       CONFIGURATION SECTION.

       INPUT-OUTPUT SECTION.

       FILE-CONTROL.

       DATA DIVISION.
       FILE SECTION.
       working-storage section.
       01 k pic x.
       78 GMEM-MOVEABLE                value 2.
       78 CF-TEXT                      value 1.
       01 hWndNewOwner pic x(4) comp-5 value zeroes.
       01 retCode      pic x(4) comp-5 value zeroes.
       01 any-key      pic x.
       01 myHandle     pointer.
       01 myPointer    pointer.
       01 sub1         pic 9(5) value zeroes.
       01 mywsdata     pic x(30) value spaces.
       linkage section.
       01 datatocopy   pic x(30).
       01 datatoget    pic x(30).
       procedure division.
               call "kernel32".
              call "user32".
           call  "GlobalUnlock"
              using by value myHandle
              returning retCode
           end-call
           call  "GlobalFree" using by value myHandle
           call  "OpenClipboard"
              using by value hWndNewOwner
              returning retCode
           end-call
           if retCode = 0
              display "error"
           else
              call  "GetClipboardData"
                 using by value CF-TEXT
                 returning myHandle
              end-call
              if myHandle = null
                 display "Clipboard data not text!"
              else
                 set address of datatoget to myHandle
                 perform varying sub1 from 1 by 1
                    until sub1 > length mywsdata
                    if datatoget(sub1:1) = x"00"
                       exit perform
                    end-if
                 end-perform
                 move datatoget(1:sub1 - 1) to mywsdata
                DISPLAY mywsdata        AT 0101 ERASE EOL
                ACCEPT  k at 2480
              end-if
              call  "CloseClipboard"
           end-if
              call "GlobalFree" using by value myHandle
              cancel "user32"
              cancel "kernel32"
           stop run.