[Release/Source Code]Some API's made Easier

Posts 1–6 of 6 · Page 1 of 1
[Release/Source Code]Some API's made Easier
Well, since last few days i have been writing an application in C# for multiple stuff. In there i have been using some WinAPI's. It annoys me sometimes to use those API's in C# as they are way better used in C++ imo.

So i decided to create a Library in C++ to just import (.dll), and use it like a charm. I have been passing some of them to it, actually only have 2 of them in it, and and rand extra function that its quite useless anyway.

What is now easier:
  • Sendinput API:
    • Keyboard; (send keystrokes)
      • Params: message , hWnd
    • Mouse; (send mouse clicks)
      • Params: x, y coords
  • Get Some process Handle. (just random, first created to test, but didn't remove it)


Instead now of writing the whole API function params, you can easily just type the message/coords and it will all be done quite easily. This makes even easier for other languages to use it.

Example of usage on another language (C#):

  • Import Dll:


Code:
[DllImport("MultiAPIs.dll")]
public static extern int sendInputMsg(string message, IntPtr hWindow);

[DllImport("MultiAPIs.dll")]
public static extern int sendInputMouse(int x, int y);
  • Usage:


Code:
sendInputMsg("Hello World", windowHandle);
Code:
sendInputMouse(100,100);


  • Library Source Code:


[php]//
// Multi APIs
// Created by Bruno Monteiro in 2010
// MultiAPIs.cpp
//

#include "stdafx.h"
#include <windows.h>

extern "C" __declspec(dllexport)HANDLE GetHandle(LPCWSTR appName);
extern "C" __declspec(dllexport)int sendInputMouse(int x, int y);
extern "C" __declspec(dllexport)int sendInputMsg(char message[], HWND handle);

//basic msg sending
int sendInputMsg(char message[], HWND hWnd)
{
SetForegroundWindow(hWnd);
int msgSize = 0;

for(int i=0; message[i] != '\0'; i++)
msgSize++;

INPUT sInput; //INPUT struct used on SendInput
sInput.type = INPUT_KEYBOARD; //will be doing keyboard input, not mouse or hardware (ki)
sInput.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;

for(int i=0; i < msgSize; i++)
{
sInput.ki.wVk = ((UCHAR)VkKeyScan(message[i])); //Converts the Char to a VirtualKey
SendInput(1, &sInput, sizeof(sInput));
Sleep(10);
}

sInput.ki.wVk = (UCHAR)0x0D; //Enter, Virtual Key hex code
SendInput(1, &sInput, sizeof(sInput));

return 0;
}

int sendInputMouse(int x, int y)
{
SetCursorPos(x,y);

INPUT sInput; //INPUT struct used on SendInput
sInput.type = INPUT_MOUSE; //will be doing mouse input, not keyboard or hardware (mi)
sInput.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; //left button press
SendInput(1, &sInput, sizeof(sInput)); //sends Mouse left buttom Down Press
sInput.mi.dwFlags = MOUSEEVENTF_LEFTUP; //left button release
SendInput(1, &sInput, sizeof(sInput)); //obvious?

return 0;
}

//gets processs HANDLE (opened ready for hacking) by it's name
HANDLE GetOpenHandle(LPCWSTR appName)
{
DWORD* idProcess = new DWORD;
GetWindowThreadProcessId(FindWindow(0, appName), idProcess);
return OpenProcess(PROCESS_ALL_ACCESS, 0, *idProcess);
} [/php]

It's Still small, but i will keep updating it whenever i have time and feel like it.

Now feel free to compare the code with usage and without the usage of the dll.

ATTENTION: I'm not a very well coder using APIs, but i keep trying my best, as result probably those API's code could be better. Still, use it if you want.


Viruscan:
VirusTotal

For those who might wand the Dll:
Download Attachment at the end
MultiAPIs.rarattachment deleted · 16 downloads before removal
Nice Work.



/Approved
Why use C# for that tho, you know C++ why not use it o_O
Quote Originally Posted by Hell_Demon View Post
Why use C# for that tho, you know C++ why not use it o_O
sexy forms
SendInputMessage simulates one character press at a time? Isn't that a little CPU consuming if you use it plenty?

Regardless, great work.
Quote Originally Posted by Void View Post
SendInputMessage simulates one character press at a time? Isn't that a little CPU consuming if you use it plenty?

Regardless, great work.
Yea it does, i could create an array of that struct, and send the whole input at one time, but still not much difference i guess?
Posts 1–6 of 6 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?