[fpc-pascal] GetClipboardFormatName causing an Error 216

Alexander Grotewohl alex at dcclost.com
Thu Dec 31 01:56:12 CET 2020


Your

FN:='';

is clobbering the pointer 'FN' with nonsense.

Just leave that line out, it isn't necessary. Or do like FN^:=#0; if you want C-string like functions to report zero length..


--
Alexander Grotewohl
https://dcclost.com
________________________________
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> on behalf of James Richters via fpc-pascal <fpc-pascal at lists.freepascal.org>
Sent: Wednesday, December 30, 2020 7:09 PM
To: 'FPC-Pascal users discussions' <fpc-pascal at lists.freepascal.org>
Cc: James Richters <james.richters at productionautomation.net>
Subject: [fpc-pascal] GetClipboardFormatName causing an Error 216

I'm trying to write a programs to get data from the windows clipboard that
was put into it with Notepad++ using vertical editing.
It uses a non-standard format and I'm trying to figure it out.
GetClipboardFormatName is supposed to get me the name of non-standard
formats,
but whenever I try to run it, I get a runtime error 216

I found some python code at: https://gist.github.com/adam-p/2514182 that I'm
trying to convert to FPC.
My fork is at:
https://gist.github.com/Zaaphod/7d94e1d712a5b9ac2bcb0bc79f039a63 Which shows
both the original python code and my FPC attempt

It works fine for standard formats:

Running "i:\programming\gcode\test\clipboard formats.exe "
Number of formats: 4
13 CF_UNICODETEXT
16 CF_LOCALE
1 CF_TEXT
7 CF_OEMTEXT

But if I highlight some text in Notepadd++ using vertical editing, holding
down Shift and ALT while using the arrow keys to highlight a block of text,
and the copy that to the clipboard, I get the following:

Running "i:\programming\gcode\test\clipboard formats.exe "
Number of formats: 6
13 CF_UNICODETEXT
49882
Runtime error 216 at $774C246C
  $774C246C
  $76932F63
  $76932EB7
  $004017EC  main,  line 60 of i:/programming/gcode/test/clipboard
formats.pas
  $00408F67

Line 60 is:
               GetClipboardFormatName(Format_Id,FN,250);

It only gets run for non-standard formats.  As I understand it that's all it
us supposed to be used for.

It's pretty short program so I pasted it below.

Any ideas on what I'm doing wrong here?

James

---------------------------------------------


uses
   Windows,strings;
Type
   BT = Record
      BT_ID: Byte;
      BT_Name: String;
   End;

Const
builtin_type: Array [0..22] of BT = (
{ 0} (BT_ID:2   ;BT_Name:'CF_BITMAP'         ),
{ 1} (BT_ID:8   ;BT_Name:'CF_DIB'            ),
{ 2} (BT_ID:17  ;BT_Name:'CF_DIBV5'          ),
{ 3} (BT_ID:5   ;BT_Name:'CF_DIF'            ),
{ 4} (BT_ID:130 ;BT_Name:'CF_DSPBITMAP'      ),
{ 5} (BT_ID:142 ;BT_Name:'CF_DSPENHMETAFILE' ),
{ 6} (BT_ID:131 ;BT_Name:'CF_DSPMETAFILEPICT'),
{ 7} (BT_ID:129 ;BT_Name:'CF_DSPTEXT'        ),
{ 8} (BT_ID:14  ;BT_Name:'CF_ENHMETAFILE'    ),
{ 9} (BT_ID:15  ;BT_Name:'CF_HDROP'          ),
{10} (BT_ID:16  ;BT_Name:'CF_LOCALE'         ),
{11} (BT_ID:18  ;BT_Name:'CF_MAX'            ),
{12} (BT_ID:3   ;BT_Name:'CF_METAFILEPICT'   ),
{13} (BT_ID:7   ;BT_Name:'CF_OEMTEXT'        ),
{14} (BT_ID:128 ;BT_Name:'CF_OWNERDISPLAY'   ),
{15} (BT_ID:9   ;BT_Name:'CF_PALETTE'        ),
{16} (BT_ID:10  ;BT_Name:'CF_PENDATA'        ),
{17} (BT_ID:11  ;BT_Name:'CF_RIFF'           ),
{18} (BT_ID:4   ;BT_Name:'CF_SYLK'           ),
{19} (BT_ID:1   ;BT_Name:'CF_TEXT'           ),
{20} (BT_ID:6   ;BT_Name:'CF_TIFF'           ),
{21} (BT_ID:13  ;BT_Name:'CF_UNICODETEXT'    ),
{22} (BT_ID:12  ;BT_Name:'CF_WAVE'           ));

Var
   i,j,Number_Of_Formats : Byte;
   Format_ID : DWord;
   FN : LPTSTR;
   Format_Name : String;

Begin
   FN:=StrAlloc (255);
   OpenClipboard(0);
   Number_Of_Formats := CountClipboardFormats();
   Writeln('Number of formats: ',Number_Of_Formats);
   format_id := 0;
   for i := 1 to Number_Of_Formats do
      Begin
         Format_Name := 'FAILED';
         Format_ID:=EnumClipboardFormats(Format_ID);
         For J:= 0 to 22 do
            Begin
               If Format_ID = builtin_type[J].BT_ID then
                  Format_Name := builtin_type[J].BT_Name;
            End;
         If Format_Name = 'FAILED' Then
            Begin
               FN:='';
               Writeln(Format_ID);
               GetClipboardFormatName(Format_Id,FN,250);
               Writeln(FN);

               If strpas(FN) <> '' Then
                  Format_Name := StrPas(FN);
            End;
         Writeln(Format_ID,' ',Format_Name);
     End;
CloseClipboard();
End.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20201231/6b871296/attachment-0001.htm>


More information about the fpc-pascal mailing list