CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2008
    Posts
    61

    ZwTerminateProcess failed with [DllImport]

    I just want to use ZwTerminateProcess() native function through my C# Application.
    I've been written this part of code :
    Code:
    [DllImport("ntdll.dll")]
            public static extern NtStatus ZwTerminateProcess(
                [In]    [Optional] IntPtr ProcessHandle,
                [In]    NtStatus ExitStatus
                );
    but the compiler issues some error code :
    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 ?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: ZwTerminateProcess failed with [DllImport]

    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.

  3. #3
    Join Date
    Jul 2008
    Posts
    61

    Re: ZwTerminateProcess failed with [DllImport]

    It's just for learning purpose dear dear arjay, I know what you are saying
    may help me?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: ZwTerminateProcess failed with [DllImport]

    All you have to do is to define NtStatus.

  5. #5
    Join Date
    Jul 2008
    Posts
    61

    Re: ZwTerminateProcess failed with [DllImport]

    I think if found the answer, I should define it as :
    typedef int NTSTATUS
    how to add this to C#?

  6. #6
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: ZwTerminateProcess failed with [DllImport]

    Quote Originally Posted by escap3 View Post
    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured