Hey guys,
I'm coding a .dll, and from that .dll, when injected, it opens a PromptCommand window, and there i'll print out some instructions.
First of all, I should say that I coded this in VisualStudio2010, and it ran perfectly. Now I've upgraded to VisualStudio2013, and this problem appears.
I've considered the fact that it might be a VS2013 bug, but I'd like to see all possibilities before I make any other move.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <iostream>
#include <stdio.h>
#include <Windows.h>
int Foo(){
// ---------------- CONSOLE ------------------//
AllocConsole(); //
SetConsoleTitle(L"Exercises Foo"); //
DETACHED_PROCESS; //
freopen("CONOUT$", "w", stdout); //
// -------------------------------------------//
while (!GetAsyncKeyState(VK_F1))
{
//system("cls");
//std::cout.clear();
std::cout << "F" << std::endl;
std::cout << "O" << std::endl;
std::cout << "O" << std::endl;
}
FreeConsole();
return 0;
}
DWORD WINAPI Main_thread(LPVOID lpParam)
{
Foo();
return S_OK;
}
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD _reason,
LPVOID lpReserved
)
{
if (_reason == DLL_PROCESS_ATTACH)
{
CreateThread(0, 0x1000, &Main_thread, 0, 0, NULL);
}
return TRUE;
}
|
Now, when I run this code, as it is, it runs perfectly..
However, when I uncomment
system("cls"); or
std::cout.clear();, my problems start to begin.
[1] system("cls");
When I uncomment this line and run it, it clears the screen everytime it re-enters the loop.
BUT, it also
DOES NOT PRINT OUT A NEW LINE, instead, it prints out 2 unrecognizable characters.
I've tryed setting
freopen function to
"w", "wb", "wt", and none of them fixed my problems. In fact, one of them (idk which) prints out only 1 unrecognizable character, but it doesn't matter because it didn't solve the problem.
[2] std::cout.clear();
When I uncomment this line and run it, it
DOES PRINT A NEW LINE, however, it does not clear the screen.
How do I get it to clear the console & to print out a new line.