Hello DaniWeb!
I've been learning how to use the fstream header, and I'm able to make a file, and write to that file, or read from that file. Now what I want to do, is create a library to be injected into the notepad process. Once it's injected, I want to be able to hit a hotkey, and have the library output a message. I've been able to achieve, somewhat of this, only not the way I want.
Here is the source.
#include <windows.h>
#include <fstream>
#include <iostream>
using namespace std;
void in()
{
ofstream file;
file.open("test.txt");
file << "Testing out this message in notepad.\n";
file.close();
}
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBox(0, L"Injected into notepad", L"Injected", MB_OK);
//case DLL_THREAD_ATTACH:
//case DLL_THREAD_DETACH:
//case DLL_PROCESS_DETACH:
break;
}
if (GetKeyState(VK_CONTROL))
{
in();
}
return TRUE;
}
As you can see, this will give me a messagebox once it has attached to the process, the text file I am using will be called test.exe. When I open test.exe, I get prompted by the messagebox, then when I hit CTRL, nothing happens. Once I close notepad though, the message is than output into test.exe and saved, so the next time I open it, I can see the message.