[MinGW-Users] Problems using AddClipboardFormatListener, RemoveClipboardFormatListener and WM_CLIPBOARDUPDATE

アーカイブの一覧に戻る
Eli Zaretskii eliz****@gnu*****
Tue Nov 26 05:05:03 JST 2024


> From: Paul Dewhirst <paul4****@gmail*****>
> Date: Mon, 25 Nov 2024 18:24:14 +0000
> 
> I've written a simple program which reports data placed on the clipboard.
> It uses AddClipboardFormatListener, RemoveClipboardFormatListener and
> WM_CLIPBOARDUPDATE.
> It compiles OK with the Microsoft C/C++ compiler, but fails to compile with gcc.
> 
> The first problem is "error: 'WM_CLIPBOARDUPDATE' undeclared".  So I added
> "#define WM_CLIPBOARDUPDATE 0x031D" to the program.  Now it fails to link with
> "undefined reference to `AddClipboardFormatListener'" and "undefined
> reference to
> `RemoveClipboardFormatListener'".
> 
> The winuser.h and libuser32.a in my installation of gcc do not contain
> these items.
> Perhaps if I download the latest win32api it will have files which do
> contain these items.
> I downloaded w32api-5.3.4-mingw32-dev.tar.xz and extracted winuser.h
> and libuser32.a,
> but these don't contain the items either.
> 
> So I produced my own header and library file to include these items.
> I used the details for OpenClipboard as a guide because this has the
> same parameter
> and result profile.
> 
> File listener.h:
> #define WM_CLIPBOARDUPDATE 0x031D
> WINUSERAPI BOOL WINAPI AddClipboardFormatListener (HWND);
> WINUSERAPI BOOL WINAPI RemoveClipboardFormatListener (HWND);
> 
> File listener.def:
> LIBRARY user32.dll
> EXPORTS
> AddClipboardFormatListener at 4
> RemoveClipboardFormatListener at 4
> 
> Then run dlltool:
> dlltool -d listener.def -l libextra.a
> 
> Then compile using these files:
> gcc -g -o c:\bin\clip_view.exe clip_view.c -L. –lextra
> 
> This compiles and links but it fails when run with "The procedure entry point
> AddClipboardFormatListener at 4 could not be located in the dynamic link
> library user32.dll.
> Using findstr /m, AddClipboardFormatListener is found in user32.dll but
> AddClipboardFormatListener at 4 is not found.  Using findstr /m,
> OpenClipboard is found
> in user32.dll but OpenClipboard at 4 is not found.  I do not understand why
> AddClipboardFormatListener fails but OpenClipboard works.
> 
> If I comment out the function declarations in listener.h and remove
> the @4 in listener.def,
> rerun dlltool and recompile, it compiles, links and runs OK.  I don't
> like doing this because
> the calling conventions won't agree.  Perhaps it is OK for
> AddClipboardFormatListener
> which is only called once, but might cause problems for something
> called repeatedly.
> Can anybody work out what is going on here?
> 
> I compared a user32.def generated using pexports-0.48-mingw32-bin from
> my Windows 7
> user32.dll with the user32.def from w32api-5.3.4-mingw32-src (with the
> @nn stripped).
> There are about 200 differences.  I think it would be a big job to
> update all the
> header files and the library file for these differences, so I don't
> expect it to happen.
> So it would be good if we could sort out using our own header and library files
> to include the needed missing items.

Instead of trying to create an import library, you could just load the
functions dynamically, using LoadLibrary and GetProcAddress.  Then
call these functions via function pointers obtained from
GetProcAddress.



More information about the MinGW-Users mailing list
アーカイブの一覧に戻る