// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "ProcessEnvironmentBlock.h"

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	DWORD ourBaseAddress = (DWORD)hModule; // Yes, this is valid. See http://blogs.msdn.com/b/oldnewthing/archive/2004/06/14/155107.aspx

	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
		PEB* peb;
		MY_PEB* mpeb;

		peb = getPEBWithASM();
		mpeb = (MY_PEB*)peb;

		// The PEB has three linked lists of the loaded modules. Modify the
		// 2nd one to make this DLL appear first (immediately after the
		// exe module itself) rather than last (where it is now):
		promoteToFirstInMemDLL(mpeb, ourBaseAddress);
		OutputDebugString(TEXT("    [InterferenceDLL::DllMain] Initialization complete.\n"));
		break;
	case DLL_THREAD_DETACH:
		OutputDebugString(TEXT("    [InterferenceDLL::DllMain] THREAD DETACH event / getting unloaded!\n"));
		break;
	case DLL_PROCESS_DETACH:
		OutputDebugString(TEXT("    [InterferenceDLL::DllMain] PROCESS DETACH event / getting unloaded!\n"));
		break;
	}
	return TRUE;
}

