Hello all. I'm working on a simple game at the moment and thus I started heading in the direction of windows hooks. I easily got the low level keyboard hook working. But of course I had to attempt the other version which uses dll's for hooking. After many attempts at this with no success I figured I would try a simpler more "hello world" type dll tutorial. Here is my problem.

I'm currently using visual studio 2008 and I have the 3 supposed files needed for this to work.

The dll file:

#include "MyHook.h"
#include <string.h>

MYHOOK_API int AddNumbers(int x, int y){
    return x + y;
MYHOOK_API int GetMessage(char* x, int length){
        strcpy(x, "hello from dll");
        return 0;
        return -1;

The header file:

#ifndef MYHOOK_H
#define MYHOOK_H

#define MYHOOK_API __declspec(dllexport)
#define MYHOOK_API

MYHOOK_API int AddNumbers(int, int);
MYHOOK_API int GetMessage(char*, int);


And the def file:

; MyHook.def : Declares the module parameters for the DLL.

LIBRARY      "myhook"
DESCRIPTION  "MyHook Windows Dynamic Link Library"

    ; Explicit exports can go here

    ; Pragma sections

When I try to compile the project I get this error:

1>------ Build started: Project: kbhook, Configuration: Debug Win32 ------
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\cpp\kbhook\Debug\kbhook.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\william78\Desktop\cpp\kbhook\kbhook\Debug\BuildLog.htm"
1>kbhook - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

If somebody could help me out here it would be greatly appreciated.

It seems the compiler is looking for the definition of the int main() function but it can't find it, but you want to make a DLL. The problem is you're compiling the code as an application (.exe) instead of a dynamic library (.dll).

Go to project properties -> General -> Configuration Type

Configuration type should be Dynamic Library (.dll)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.