Hi,

I have been trying awhile for weeks to do dll injection. Found several ways such as CreateRemoteThread(), SetWindowsHookEx() and Code Cave method. Currently working on CreateRemoteThread(), I have read up A LOT on it. Finally i managed to grab hold of it quite abit. But I'm still left with one last problem. I'm sure the code is injected into the remoteprocess, but the remote process crashes immediately after the code is injected.

Attached is the main highlights that the error should reside in.

Code:
typedef void (WINAPI *_GetModuleHandle)(LPCTSTR);

typedef struct MyData {
    TCHAR dll_data_name[128];
    HANDLE (WINAPI * _GetModuleHandle)(LPCTSTR);
} MYDATA, *PMYDATA;

DWORD WINAPI MyThreadFunction( LPVOID lpParam )
{
    PMYDATA prd = (PMYDATA)lpParam;
    prd->_GetModuleHandle(prd->dll_data_name);
    return 0;
}

BOOL Inject(DWORD pID, char * DLL_N)
{
   HANDLE Proc, hThread;LPVOID RemoteString;MYDATA * VirtualAllooo;HMODULE hModule;

   DWORD dwNumBytesXferred = 0, dwThreadId = 0;

   hModule = LoadLibrary("Project1");

   MYDATA *dataLocal = {(PMYDATA)GetProcAddress(hModule, "Function")};

   Proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);

   VirtualAllooo = (MYDATA*)VirtualAllocEx(Proc, NULL, sizeof(MYDATA), MEM_COMMIT, PAGE_EXECUTE_READWRITE);

   WriteProcessMemory(Proc, VirtualAllooo, &dataLocal, sizeof(MYDATA), &dwNumBytesXferred);

   RemoteString = (LPVOID)VirtualAllocEx(Proc, NULL, strlen(DLL_N), MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);

   WriteProcessMemory(Proc, (LPVOID)RemoteString, DLL_NAME, strlen(DLL_N), NULL);

   hThread = CreateRemoteThread(Proc, NULL, 0, (LPTHREAD_START_ROUTINE)RemoteString, VirtualAllooo, 0, &dwThreadId);
   return true;
}

What went wrong here?