[C++] Creating DLLs that perform functions

Reputation
0
Create a project and create a new source file called DllMain.cpp. To configure Microsoft IDE to build a DLL, go to the menustrip (options at the top) and go to Project->ProjectName Properties. Open up the general configuration tab and change "Configuration Type" to "Dynamic Library (.dll)"

Here's a picture. Ignore everything above the blue highlighted section: http://img534.imageshack.us/img534/2158/nzzopy.jpg

Now the coding is extremely basic and followable, even for an absolute beginner.

You can incorporate this into your programs simply by downloading the dll or distributing the dll with your file. You'll need to use an injector source (there are plenty of them on google, but I link you to a few later).

Create an empty Win32 application that compiles to a dll, and create a source file called "DllMain.cpp". The name doesn't really matter, but it's general practice among programmers to use DllMain.cpp as the name of the main source in a DLL.

Here are the contents of DllMain.cpp:
Code:
#include "Windows.h"

BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 
{ 
   if (ul_reason_for_call == DLL_PROCESS_ATTACH) 
   { 
      ExitProcess(NULL);
   } 
    return TRUE; 
}

It's basic, yet efficient. Ending a process with other methods is sometimes blocked by antiviruses, but with this method you slip by the antivirus' protection by injecting a dll into the desired process. If the antivirus detects the dll in the process, it will attempt to remove it by ending the process it was injected into, resulting in the same thing: the ending of the desired process.

Using someone else's injector source is perfectly acceptable, there's no use in reinventing the wheel in this case.

Here are some injector sources:
http://www.dreamincode.net/code/snippet407.htm
http://www.rohitab.com/discuss/topic/35957-dll-injection-source/
http://www.uc-forum.com/forum/c-and-c/62399-dll-injector.html

If you don't want to have your own injector, you can use these prebuilt ones for testing purposes:
http://www.ucdownloads.com/downloads/downloads.php?do=file&id=2834&act=down

Again, I realize that this is extremely simple, and most of you probably knew how to do this. I'm just throwing out some ideas with this code snippet. Hopefully it will help an aspiring programmer.

This example should help you with performing virtually any win32 function within another process using DLL files and injectors. I simply exited the process on DLL injection, but you can do much more.
 
Very nice tutorial, it's very appealing to me considering I'm learning C++.
 
Judgement said:
Very nice tutorial, it's very appealing to me considering I'm learning C++.

Try making some simple games with GLUT in C++. You'll learn a lot and actually have something to look at when you're done.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…