Thread: Want to run .dll when a program is started

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    24

    Want to run .dll when a program is started

    I only have C console programming experience.
    But i would like to make a .dll that i can put in my c:\windows\system32 folder.

    As everytime i open my calculator my numlock goes off.

    I would like the .dll to start when calculator is opened, wait for 2 seconds, then check if the numlock key is active, if it isn't press it down.

    I have been looking up info about global hooks, but can't seem to make heads or tails of it.

    Anyone have some ideas or code they can through at me?

    Thanks.

    I use Borland C++ 3 Biulder on Win XP

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    1. Rename calc.exe to calc_old.exe
    2. Create a new program named calc.exe
    Code:
    int WinMain(...)
    {
        ...
    
        CreateProcess("calc_old.exe", ...);
        WaitForInputIdle(pi.hProcess, 3000);
    
        // Activate num lock...
        ...
    }
    3. Copy your new program (calc.exe) to "c:\windows\system32".

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    24
    ok i can get that to work, but id like to put it in a .dll if possible, as i would like to apply it to other prorams when they are started

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    There are a few options:
    • Use the AppInit_DLLs registry value. This will load your dll into every process. This may slow down your computer.
    • Wait until calc starts and then set a hook on its main thread (pi.hThread). The type of hook does not matter as we are just using this method to get our dll loaded in the calc process.
    • Wait until calc starts and insert the dll using CreateRemoteThread. This is done by using LoadLibrary as the thread procedure. There are examples on this board and the web. I recommend using no. 2 rather than this method.
    • Alter calc.exe so it links with your DLL.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help on making program run more efficiently
    By peeweearies in forum C Programming
    Replies: 2
    Last Post: 03-23-2009, 02:01 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. Help me with my basic program, nothing I create will run
    By Ravens'sWrath in forum C Programming
    Replies: 31
    Last Post: 05-13-2007, 02:35 AM
  4. Help Me Get Started On A program
    By rainmanddw in forum C++ Programming
    Replies: 2
    Last Post: 08-20-2004, 05:05 PM
  5. program won't run standalone
    By richard in forum C++ Programming
    Replies: 2
    Last Post: 07-20-2002, 06:21 PM