4
votes

I want to write a tool to capture and visualize pressed keys in a specific application so I searched for a sample source.

My result was this:

http://www.codeguru.com/cpp/w-p/system/keyboard/article.php/c5699

But it doesn't work yet. Here's my approach:

I have imported the sources as makefile project in Elipse (Helios, CDT Version 7.0.0.201006141710) using Mingw 4.6.1 as toolchain.

In keydll3.cpp I added the line

#define KEYDLL3_EXPORTS

to tell the preprocessor that i want to export the dll functions.

Now when I try to compile the project, the following errors occour:

    **** Internal Builder is used for build               ****
    g++ -shared -DBUILDING_EXAMPLE_DLL -IC:\MinGW\include -IC:\MinGW\lib\gcc\mingw32\4.6.1\include\c++ -O2 -g -Wall -c -fmessage-length=0 -oStdAfx.o ..\StdAfx.cpp
    g++ -shared -DBUILDING_EXAMPLE_DLL -IC:\MinGW\include -IC:\MinGW\lib\gcc\mingw32\4.6.1\include\c++ -O2 -g -Wall -c -fmessage-length=0 -okeydll3.o ..\keydll3.cpp
    ..\keydll3.cpp:31:0: warning: ignoring #pragma data_seg  [-Wunknown-pragmas]
    ..\keydll3.cpp:34:0: warning: ignoring #pragma data_seg  [-Wunknown-pragmas]
    ..\keydll3.cpp:36:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
    g++ -okeydll3 keydll3.o StdAfx.o
    c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../libmingw32.a(main.o): In function `main':
    C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `WinMain@16'
    collect2: ld returned 1 exit status
    Build error occurred, build is stopped

It seems that the compiler misses the winmain statement because he assume it's a windows application. But a dll isn't. It also seems that the "-share" option has no effect.

So how do I tell the compiler that my code is a dll with some Windows API calls?

If there's another example which works without visual studio let me know.

Thanks in advance for your contributions.

Noir

1

1 Answers

4
votes

You've added the -shared option in the wrong place. It needs to be added to the linker flags, not to the compiler flags. Your commands should look like this.

g++ -DBUILDING_EXAMPLE_DLL -IC:\MinGW\include -IC:\MinGW\lib\gcc\mingw32\4.6.1\include\c++ -O2 -g -Wall -c -fmessage-length=0 -oStdAfx.o ..\StdAfx.cpp
g++ -DBUILDING_EXAMPLE_DLL -IC:\MinGW\include -IC:\MinGW\lib\gcc\mingw32\4.6.1\include\c++ -O2 -g -Wall -c -fmessage-length=0 -okeydll3.o ..\keydll3.cpp
g++ -shared -okeydll3 keydll3.o StdAfx.o