Click to See Complete Forum and Search --> : ZwTerminateProcess failed with [DllImport]


escap3
February 5th, 2010, 11:22 AM
I just want to use ZwTerminateProcess() native function through my C# Application.
I've been written this part of code :

[DllImport("ntdll.dll")]
public static extern NtStatus ZwTerminateProcess(
[In] [Optional] IntPtr ProcessHandle,
[In] NtStatus ExitStatus
);

but the compiler issues some error code :

Error 2 The type or namespace name 'NtStatus' could not be found (are you missing a using directive or an assembly reference?)


how Can I import this function ?

Arjay
February 5th, 2010, 01:46 PM
There's really no need to try to pinvoke to a kernel mode api when in user mode.

If you are trying to terminate a project, you can use the Process class methods or pinvoke to TerminateProcess api.

escap3
February 5th, 2010, 02:29 PM
It's just for learning purpose dear dear arjay, I know what you are saying :)
may help me?

Arjay
February 5th, 2010, 03:05 PM
All you have to do is to define NtStatus.

escap3
February 5th, 2010, 03:55 PM
I think if found the answer, I should define it as :
typedef int NTSTATUS
how to add this to C#?

nelo
February 5th, 2010, 07:10 PM
I think if found the answer, I should define it as :
typedef int NTSTATUS
how to add this to C#?

I don't think you have to define that. Just treat it as an 'int' (i.e. instead of using NTSTATUS use Int32 or int).