Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Convert This Code to C#

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Morph.C
Cheater
Reputation: 0

Joined: 15 Aug 2009
Posts: 29

PostPosted: Thu Aug 27, 2009 5:41 pm    Post subject: Convert This Code to C# Reply with quote

Hello everyone, I have a problem, I have spent almost all my code the a dll injector, from Delphi to C#, but the problem is the "GetPid" Function, I not can convert it, someone could do me the please of converting the code to C#?

This is The Code:

Code:
function GetPID(ProcessName: String): Cardinal;
begin
  Result:=0;
  SnapShotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  MyProcessEntry.dwSize:=SizeOf(TProcessEntry32);
  if not (Process32First(SnapShotHandle, MyProcessEntry)) then
     Exit;
  repeat
  if (ProcessName = MyProcessEntry.szExeFile) then
     Result := MyProcessEntry.th32ProcessID;
until not (Process32Next(SnapShotHandle, MyProcessEntry));
end;


Thanks In Advance. And. if you not want, don't tell me stupid words.
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Thu Aug 27, 2009 8:03 pm    Post subject: Reply with quote

Code:
public int GetPID(String ProcessName)
{
 return Process.GetProcessesByName(ProcessName)[0].Id;
}

or
Code:
public int GetPID(String ProcessName)
{
 return Process.GetProcessesByName(ProcessName).Id;
}


Not tested, but should work.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Aug 27, 2009 10:21 pm    Post subject: Reply with quote

Yeah, just use the process class.

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx
Back to top
View user's profile Send private message
Morph.C
Cheater
Reputation: 0

Joined: 15 Aug 2009
Posts: 29

PostPosted: Thu Aug 27, 2009 10:26 pm    Post subject: Reply with quote

Oh man, not works. i create a new thread, with my full code to see if anyone can help me.

Until then thanks for trying to help.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Aug 27, 2009 11:10 pm    Post subject: Reply with quote

Code:
Process[] proc = Process.GetProcessesByName("process name"); //don't add the .exe part!
Back to top
View user's profile Send private message
Morph.C
Cheater
Reputation: 0

Joined: 15 Aug 2009
Posts: 29

PostPosted: Thu Aug 27, 2009 11:45 pm    Post subject: Reply with quote

slovach wrote:
Code:
Process[] proc = Process.GetProcessesByName("process name"); //don't add the .exe part!


Man!!, this is the problem, this function any select the process with extentions ".exe" and i want to atach a process with a extention ".gme" you understand me? ¬¬..

Sorry but this code not can, see my next post maybe you can Fix the problem! Thanks for you time.
Back to top
View user's profile Send private message
FullyAwesome
I post too much
Reputation: 0

Joined: 05 Apr 2007
Posts: 4438
Location: Land Down Under

PostPosted: Fri Aug 28, 2009 12:56 am    Post subject: Reply with quote

Morph.C wrote:
slovach wrote:
Code:
Process[] proc = Process.GetProcessesByName("process name"); //don't add the .exe part!


Man!!, this is the problem, this function any select the process with extentions ".exe" and i want to atach a process with a extention ".gme" you understand me? ¬¬..

Sorry but this code not can, see my next post maybe you can Fix the problem! Thanks for you time.


i've got no idea what the fuck you're trying to see, but you can always edit the string and remove everything after the '.' .

_________________
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Aug 28, 2009 12:57 am    Post subject: Reply with quote

Morph.C wrote:
slovach wrote:
Code:
Process[] proc = Process.GetProcessesByName("process name"); //don't add the .exe part!


Man!!, this is the problem, this function any select the process with extentions ".exe" and i want to atach a process with a extention ".gme" you understand me? ¬¬..

Sorry but this code not can, see my next post maybe you can Fix the problem! Thanks for you time.


It returns an array of processes that match that name, if multiple processes share the same name, it will return them all.

If that .gme thing is an actual process, it will probably come up fine.


You can also try using the GetProcesses method to return all running processes. Did you even read the link I posted?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites