Click here to Skip to main content
15,920,602 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:

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

inner source.;;

please

Posted
Updated 23-Nov-09 2:00am
v2

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.

 
Share this answer
 

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:

C#
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);
}
 
Share this answer
 
p/invoke ? He's only tagged it as a C++ question.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900