本文介绍了createThread()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要createThread(LPSECURITY_ATTRIBUTES lpThreadAttributes,SIZE_T dwStackSize,LPTHREAD_START_ROUTINE lpStartAddress,LPVOID lpParameter,DWORD dwCreationFlags,LPDWORD lpThreadId);

I want createThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);

内部来源;;

推荐答案


using System;
using System.Runtime.InteropServices;

public class NativeMethods
{
    #region CreationFlags

    /// <summary>
    /// The thread runs immediately after creation.
    /// </summary>
    public const int CREATE_IMMEDIATE = 0;
    /// <summary>
    /// The thread is created in a suspended state, and does not run until the ResumeThread function is called.
    /// </summary>
    public const int CREATE_SUSPENDED = 0x00000004;
    /// <summary>
    /// The dwStackSize parameter specifies the initial reserve size of the stack. If this flag is not specified, dwStackSize specifies the commit size.
    /// </summary>
    /// <remarks>Windows 2000: The STACK_SIZE_PARAM_IS_A_RESERVATION flag is not supported.</remarks>
    public const int STACK_SIZE_PARAM_IS_A_RESERVATION = 0x00010000;

    #endregion

    // http://msdn.microsoft.com/en-us/library/ms686736(VS.85).aspx
    /// <summary>
    /// Delegate to a method that serves as the starting address for a thread.
    /// </summary>
    /// <param name="lpParameter">The thread data passed to the function using the lpParameter parameter of the CreateThread, CreateRemoteThread, or CreateRemoteThreadEx function.</param>
    /// <returns>Indicates the success or failure of the function.</returns>
    public delegate int ThreadProc(IntPtr lpParameter);

    // http://msdn.microsoft.com/en-us/library/aa379560(VS.85).aspx
    /// <summary>
    /// Contains the security descriptor for an object and specifies whether the handle retrieved by specifying this structure is inheritable.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct SECURITY_ATTRIBUTES
    {
        /// <summary>
        /// The size, in bytes, of this structure.
        /// </summary>
        int nLength;
        /// <summary>
        /// A pointer to a security descriptor for the object that controls the sharing of it.
        /// </summary>
        IntPtr lpSecurityDescriptor;
        /// <summary>
        /// Specifies whether the returned handle is inherited when a new process is created.
        /// </summary>
        bool bInheritHandle;
    }

    // http://msdn.microsoft.com/en-us/library/ms682453(VS.85).aspx
    /// <summary>
    /// Creates a thread to execute within the virtual address space of the calling process.
    /// </summary>
    /// <param name="lpThreadAttributes">A SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes.</param>
    /// <param name="dwStackSize">The initial size of the stack, in bytes.</param>
    /// <param name="lpStartAddress">A delegate to the method to be executed by the thread.</param>
    /// <param name="lpParameter">A pointer to a variable to be passed to the thread.</param>
    /// <param name="dwCreationFlags">The flags that control the creation of the thread.</param>
    /// <param name="lpThreadId">Receives the thread identifier.</param>
    /// <returns>If the function succeeds, the return value is a handle to the new thread.</returns>
    [DllImport("kernel32.dll")]
    public static extern IntPtr CreateThread(
        SECURITY_ATTRIBUTES lpThreadAttributes,
        int dwStackSize,
        ThreadProc lpStartAddress,
        IntPtr lpParameter,
        int dwCreationFlags,
        out int lpThreadId);
}



这篇关于createThread()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 12:50