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 6966337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:10:44+00:00 2026-05-27T16:10:44+00:00

i have one solution file in visual studio, and i have in it two

  • 0

i have one solution file in visual studio, and i have in it two projects one for the .dll file and one other project to the .c file:

this is the .h file:

#include <windows.h>

#ifndef BHANNAN_TEST_CLASS_H_
#define BHANNAN_TEST_CLASS_H_

extern int __declspec (dllexport) Factorial(int n);

#endif 

and in .c file (of the dll ):

#include "hanan.h"
#include <stdio.h>

int Factorial(int n) {
  printf("in DLL %d \n" ,n);

  return 0;
}

now i have a loader/tester which i try from it to load the dll to hook keystrokes in notepad, just to understand the mechanism of the hooking.

this is the code of the loader:

#include <windows.h>
#include <stdio.h>

typedef int (*functor) (int);
functor funcptr =NULL;

int main () {

    HWND windowHandle;
    HINSTANCE hMod;
    HOOKPROC lpfn; 
    DWORD threadId;
    HHOOK hook;
    HMODULE myDLL = LoadLibraryW(L"dll123.dll");
    funcptr = (functor) GetProcAddress(myDLL,"Factorial");

    /// printing issues:////////////////
    printf("%d \n\r" , myDLL);
    printf("%d" , funcptr(33));
    //////////////////////////////////////

    lpfn = (HOOKPROC) funcptr;
    hMod = myDLL;
    windowHandle = FindWindow(L"Notepad",NULL);
    threadId = GetWindowThreadProcessId(windowHandle, NULL);

    hook = SetWindowsHookEx(WH_KEYBOARD,lpfn,hMod,threadId);//(WH_CBT, HookCBTProc, hInst, threadId);

    /// printing issues:
    printf("%d %d %d %d\n" , hook, WH_KEYBOARD , lpfn , hMod);
    printf("%d %d \n",threadId , windowHandle );
    getchar();
    return 0;
}

i get all the printing no zeros, which means there are no nulls (assuming notepad is running), but when i do any keystroke in notepad i get an exception right away,

using visual studio 2010 and windows 7

added exception properties:

 Exception Offset:  0006632c
  Exception Code:   c0000409
  Exception Data:   00000000
  • 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-27T16:10:44+00:00Added an answer on May 27, 2026 at 4:10 pm

    Just a shot in the dark, but the function that you pass to the set hook call should look like this:

    LRESULT CALLBACK KeyboardProc(
      __in  int code,
      __in  WPARAM wParam,
      __in  LPARAM lParam
    );
    

    Not:
    int Factorial(int n) (where are the two other params??)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two projects in one Visual Studio 2008 solution. I'd like to use
I have two projects in my Visual Studio solution: The one is a WcfService
In Visual Studio 2008 I know its possible to have one solution with two
I have this kind of setup in my Visual Studio 2008 solution: One WCF
I have a Visual Studio solution consisting of multiple projects. In one of the
Consider this synthetic example. I have two native C++ projects in my Visual Studio
In a .net application involving several projects in one solution, I have a project
I have a solution with several projects. One of them is a setup project.
I have a solution with two service projects (one is hosting a unit test
In one C# solution I have several projects that share a CommonAssemblyInfo.cs file, so

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.