Thread: dll problem

  1. #1
    The Autodidact Dante Wingates's Avatar
    Join Date
    Apr 2010
    Location
    Valhalla
    Posts
    56

    dll problem

    Hello. I have a problem in my hands and would be glad if someone could help me... I was playing a game when I got tired of using the keyboard to send key combinations... That was when I decided to create something to do it for me... Basically Im trying to write a hook to intercept window messages to another application, in this case the game window, and then send a combinations of keystrokes to the target window if the user press key X. Sending keys is not the problem, the problem is that I cant get this dll to work.

    The problem is that calling a normal function works, but calling a function like this:

    Code:
    LRESULT __declspec(dllexport)__stdcall CALLBACK readKbMessages(void)
    {
        //some code
    }
    simply does not work.. By saying "normal function" I mean a function like void readKbMessages(). Im trying to link to it because I had created all the application logic, but could not connect to the LRESULT CALLBACK funcName(int, HOOKPROC, HINSTANCE, DWORD) function. The pointer is always null


    This is the code where I link to the dll:

    Code:
    HMODULE hDll = LoadLibraryA("dll.dll");
    
    LRESULT CALLBACK (*func)() = (LRESULT CALLBACK(*)())GetProcAddress(hDll, "readKbMessages");

    it works ok for "normal functions", but I cannot get it to work on that miserable function. The function to intercept key strokes should be similar to that one.. Also I tried every combination I could think of.... LRESULT CALLBACK __stdcall(dllexport), etc, etc, etc... Im not very used to dlls, but I wont stop until I get to the end..

    Also any info about hooking applications, intercepting window messages, etc, etc, would be great. This is the first time Im actually tryng this.

    The final application should attach to a process, get its process ID, hook to it, intercept its messages, look for the user selected key, and if matched send the user selected key combinations to the target process. Thats all

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    use dumpbin utility to check the EXPORTS of your dll

    your function has a different name in the EXPORTS list

    use this name (something like readKbMessages@0 )

    or use def file to modify it to your likings
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    The Autodidact Dante Wingates's Avatar
    Join Date
    Apr 2010
    Location
    Valhalla
    Posts
    56
    acording to dumpbin, the function is really called readKbMessages@0... I cant believe I deleted everything and started again just because of a @ and a 0... Thank you very much vart...

    Is there something I can do to keep the other name without the @0 instead of using define?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Dante Wingates View Post
    Is there something I can do to keep the other name without the @0 instead of using define?
    you can use def file to specify export names of the dll
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Losing reference between dlls
    By g4j31a5 in forum Windows Programming
    Replies: 7
    Last Post: 05-19-2010, 02:28 AM
  2. DLL Function / Load Library Problem
    By cboard_member in forum Windows Programming
    Replies: 5
    Last Post: 12-10-2005, 10:11 AM
  3. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM
  4. std::string vs char* DLL problem
    By aker_y3k in forum C++ Programming
    Replies: 13
    Last Post: 10-02-2002, 09:05 AM
  5. VCL and DLL class problem
    By borland_man in forum C++ Programming
    Replies: 1
    Last Post: 02-13-2002, 11:07 AM