void DllInjection::injectCode() // should i turn all this into throws as well :/?
{
if ((processHandle = OpenProcess( PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ,0,processID)) == NULL)
{
_InjectionStatus = CREATEHANDLE_ERROR;
return;
}
if ((memoryAddress = VirtualAllocEx(processHandle,NULL,wcslen(dllName.c_str()),MEM_COMMIT,PAGE_READWRITE)) == NULL) // check third argument, it wouldn't let me use strlen() because it doesnt deal with wide chars
{
_InjectionStatus = ALLOC_ERROR;
return;
}
if ((WriteProcessMemory(processHandle, memoryAddress, dllName.c_str(),sizeof(dllName),NULL)) == 0)
{
_InjectionStatus = WRITEPROCESS_ERROR;
return;
}
_LoadLibraryEx procAdd = (_LoadLibraryEx)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "LoadLibraryEx");
if ((CreateRemoteThread(processHandle, NULL, 0, (LPTHREAD_START_ROUTINE)procAdd, (LPVOID)memoryAddress, 0, NULL)) == NULL)
{
_InjectionStatus = CREATETHREAD_ERROR;
return;
}
_InjectionStatus = SUCCESS;
return;
}
ok now here is my dilema....How do i know what i should use c++ exceptions for vs. keeping track of an error code??
for example..in the above code if i call that function with my object,then THROW back to the caller,which is main, THE CALLED function that threw the object never knows it had an error. I think i might be confused on when i am suppose to use exceptions vs keeping track of an objects state/error codes. -thx