createThread() [英] createThread()

查看:91
本文介绍了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);

内部来源;;

推荐答案

您不会告诉我们是什么在阻止您.您已经粘贴了方法签名,因此您知道它是什么.这是什么问题?您知道足够的C ++理解所有含义吗?为什么要创建线程?除了指向MSDN的链接之外,您的问题实际上无法以任何方式回答,因为您似乎要说的是,您知道它是什么,但不知道它的工作方式或方式.

You don''t tell us what is stopping you.  You''ve pasted the method signature, so you know what it is.  What is the issue here ? Do you know enough C++ to understand what it all means ? Why do you want to create a thread ? Your question is physically impossible to answer in any way apart from links to MSDN, because what you seem to be saying is that you know what it is, but have no idea how it works, or how to do it.


为诸如此类的方法创建自己的签名通常只需要搜索" MSDN作为函数名并在其中读取信息.那就是我所做的,这就是我想出的.它未经测试,可能需要进行一些修改(PInvoke的内容通常需要进行一些操作才能正确使用),但是如果您查看注释中的链接,您应该会知道我是怎么做到的:

Creating your own signatures for methods such as this often just requires ''googling'' MSDN for the function name and reading the information there. That''s what I have done and this is what I''ve come up with. It''s untested and may need some modification (PInvoke stuff often takes a little manipulation to get just right) but if you look at the links in the comments you should see how I''ve arrived at this:

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);
}


p/调用?他只是将其标记为C ++问题.
p/invoke ? He''s only tagged it as a C++ question.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆