I have a dll(made by me in c#) and I want to auto load a function when it is injected into a process. How can I do this? An little example would be perfect for me.
PS: Sorry for my english..
PS: Sorry for my english..
#pragma unmanaged
#include<Windows.h>
#include "managedStart.h"
DWORD WINAPI ThreadProc(LPVOID lpParameter);
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CreateThread(NULL,NULL,ThreadProc,NULL,0,NULL);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
Sleep(200);
ManagedStart();
return 0;
}
Quote:
thats not posible in C#.
you have to write native code thats calls your function. The easiest is to use c++/Cli because that allows you to merge nativ code (with a dllmain) with managed code that calls your function, without having to initialize the .net by yourself.