Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 982911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:46:22+00:00 2026-05-16T04:46:22+00:00

I am trying to understand windows hooks by writing a few keyboard hooks. I

  • 0

I am trying to understand windows hooks by writing a few keyboard hooks.
I have a function:

bool WriteToFile(WPARAM keyCode, char * fileName)
{
    ofstream fout("filename");
    if(fout.is_open())
    {
        if(keyCode>=0x030 && keyCode<0x039)
            fout<< (keyCode - 0x030);
            fout.close();
        return true;
    }
    else        fout.close();
        return false;
}

…that i try to call from here but it almost always fails. Why?

LRESULT CALLBACK KbHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode > 0)
             {
                 WriteToFile(wParam,"log.txt");  //this function always fails . Why 
             }
else return CallNextHookEx(hCurrentHook, nCode, wParam, lParam);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:46:23+00:00Added an answer on May 16, 2026 at 4:46 am

    I think it’s because you’re trying to open a file called “filename”, rather than using whatever filename was provided. I assume you’re writing a keylogger. It should read:

    bool WriteToFile(WPARAM keyCode, char * fileName)
    {
        // cause output to go to the end of the file by using ios_base::app
        ofstream fout(fileName, ios_base::app);
        if(fout.is_open())
        {
            if(keyCode>=0x030 && keyCode<0x039)
                fout<< (keyCode - 0x030);
                fout.close();
            return true;
        }
        else        fout.close();
            return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to understand better how Windows sessions work, so if I have some
Just trying to understand that - I have never used it before. How is
I'm trying to understand how windows authentication / encryption works with the NetTcpBinding in
I'm trying to better understand Silverlights binding mechanism and so have created a simple
Possible Duplicate: Socket Programming for Windows C/C++ I am trying to understand what my
I am trying to understand better how Windows sessions (TS sessions and log on
I am trying to understand a certain longstanding concept in Windows Forms re: UI
I am trying to understand the ways in which an unmanaged user-mode Windows process
Situation: I have website which calls WCF Service and i'm trying to understand it..
I'm trying to understand how modal windows work. I know, there are multiple plug-ins

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.