Jump to content
  • Advertisement
Sign in to follow this  
Hermes

GetModuleHandle failed with error 6 :Invalid handle value

This topic is 4657 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i am trying to make a remote thread into an existing process...the problem is that although my dll is mapped into memory i can't get the handle to it.... here's a bit of code ...


__declspec(dllimport)HANDLE WINAPI MyFindFirstFile(LPCTSTR  str,WIN32_FIND_DATA dta);
__declspec(dllimport)DWORD searchProcessID(TCHAR* strProcName); 
__declspec(dllimport) void WINAPI ThreadProc(LPVOID lpParam);
__declspec(dllimport)void ErrorExit(LPTSTR lpszFunction); 
......................................................................
.......................................................................

	int ProcID=searchProcessID("iexplore.exe");
    HANDLE hIE=NULL;//handle to remote thread
	DWORD threadID;
	DWORD dwErr=-1;



	if((hIE=OpenProcess(PROCESS_ALL_ACCESS|PROCESS_CREATE_THREAD|PROCESS_QUERY_INFORMATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_VM_OPERATION,
		        TRUE,// inheritable
				ProcID))==NULL)
	{
	  
		std::cout<<"Could not open process for hooking "<<std::endl;
	
	}

    HMODULE hDLL=GetModuleHandle("MySleep.dll");
	ErrorExit("GetModuleHandle"); 

	PROC pThread=GetProcAddress(hDLL,"ThreadProc");
    ErrorExit("GetProcAddress"); 


	
	HANDLE hThread=CreateRemoteThread(hIE,
		               NULL,
                       0, //stack size 0=dim of hooked exe
                       (LPTHREAD_START_ROUTINE)hookThreadProc,
					   0,//parameter sent to thread
					   0,
					   &threadID);





If i call any extern function everything works fine ...i can't see what's wrong when getting the dll handle.. Do you? .....[looksaround]

Share this post


Link to post
Share on other sites
Advertisement
Well the error is in fact in the DLL



__declspec(dllexport)DWORD searchProcessID(TCHAR* strProcName)
{
DWORD procList[1024],nb,procNo;

if(!EnumProcesses(procList,sizeof(procList),&nb))
return 0;


procNo=nb/sizeof(DWORD);


for(int i=0;i&lt;procNo;i++)
{

TCHAR szProcName[MAX_PATH]=TEXT("&lt;unimportant&gt;");


HANDLE hProcess=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,procList);


//get the name of each process
if(hProcess!=NULL)
{

HMODULE hMod;
DWORD no;
if(EnumProcessModules(hProcess,&hMod,sizeof(hMod),&no))
{
GetModuleBaseName(hProcess,hMod,szProcName,sizeof(szProcName)/sizeof(TCHAR));
if(strcmp(szProcName,strProcName)==0)
{

std::cout&lt;&lt;szProcName&lt;&lt;std::endl;
return procList;
}

}


}


CloseHandle(hProcess);


}

std::cout&lt;&lt;"Handle= -1"&lt;&lt;std::endl;

return -1;

}







Still can't see why?

[Edited by - Hermes on September 24, 2005 9:00:54 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!