Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

saving in a text file

hurry-ohurry-o Member Posts: 1
Hello everyone i am a new progammer and i need some help.

i'made a program which disables the keyboard with hooks,but when it's disabled i want to save the data in a txt file. here is the code.
How i can save the data in a txt file when the keyboard is disabled.Thanks

[code]

//------------------------dll file----------------------------------
#include
#include
#include
#pragma hdrstop
#include
#include
extern "C" __declspec(dllexport) LRESULT __stdcall CALLBACK KeyboardProc(int nCode, WPARAM
wParam, LPARAM lParam)
{
//disable keyboard
if (wParam==WM_KEYUP || WM_KEYDOWN)
{
return 1;

}
return 0;
}


#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//----------------------------------------------------------------------

[/code]
[code]

//------------------------header---------------------------------------------
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include
//---------------------------------------------------------------------------

HANDLE hdll;
HANDLE h_keyboard;
HOOKPROC f_keyboard;

class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TButton *Button2;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//------------------------------------------------------------------------------



//------------------------cpp------------------------------------------------------
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{

//load the dll which contains the hooking procedures
hdll = LoadLibrary((LPCTSTR) "C:\Project1.dll");
if (hdll==NULL)
{
MessageBox(NULL,"dll not loaded","",MB_OK);
return;
}
//get the address of the keyboard procedure.
f_keyboard = (HOOKPROC)GetProcAddress(hdll, "KeyboardProc");
if (f_keyboard==NULL)
{
MessageBox(NULL,"KeyboardProc Function Address Not Found","",MB_OK);
return;
}
//install the keyboard HOOK procedure
h_keyboard = SetWindowsHookEx(WH_KEYBOARD,f_keyboard,hdll,0);
if (! h_keyboard)MessageBox(NULL,"Keyboard Hook Installation Failed","",MB_OK);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
UnhookWindowsHookEx(h_mouse);
FreeLibrary(hdll);
}
//---------------------------------------------------------------------------
[/code]
Sign In or Register to comment.