I seem to be a bit confused how the following call works:
string str = Process.GetCurrentProcess().MainModule.ModuleName;
I know it’s the same as doing the following:
Process pvar = new Process();
ProcessModule pmvar = pvar.MainModule;
string str2 = pmvar.ModuleName;
But I need a detailed explanation how it’s possible to ex. call the MainModule non-static property in the class ProcessModule since I haven’t created an instanse of the Process class explicitly!
Does the GetCurrentProcess() method automatically create an instanse to work on, since it’s not required to do so?
You haven’t created an instance of
Process, but this returns one for you:That’s very different from the
new Process()call you’ve got in the second snippet. So your first statement is actually equivalent to:GetCurrentProcess()returns a reference to aProcessobject representing the currently executing process.