CreateThread() <-- Parameter übergeben
-
hallo!
ich rufe eine funktion von mir als thread auf - dieser funktion sollen nun
aber mehrere paramter übergeben werden...wie kann ich das mit CreateThread() realisieren??
danke euch

-
gib dem thread einen pointer auf eine struct, die alle variablen enthält...
-
hmm ich habe versucht als parameter der thread-funktion nen pointer auf nen
struct zu machen aber da kam nen fehler von wegen konnte den paramater
von CreateThread() nicht in struct koverieren.wie muss ich das denn aufrufen?
-
MSDN schrieb:
CreateThread
Creates a thread to execute within the virtual address space of the calling process.
To create a thread that runs in the virtual address space of another process, use the CreateRemoteThread function.
HANDLE WINAPI CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes,
SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId
);Parameters
lpThreadAttributes
[in] A pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpThreadAttributes is NULL, the handle cannot be inherited.The lpSecurityDescriptor member of the structure specifies a security descriptor for the new thread. If lpThreadAttributes is NULL, the thread gets a default security descriptor. The ACLs in the default security descriptor for a thread come from the primary token of the creator.
Windows XP/2000/NT: The ACLs in the default security descriptor for a thread come from the primary or impersonation token of the creator. This behavior changed with Windows XP SP2 and Windows Server 2003.
dwStackSize
[in] The initial size of the stack, in bytes. The system rounds this value to the nearest page. If this parameter is zero, the new thread uses the default size for the executable. For more information, see Thread Stack Size.
lpStartAddress
[in] A pointer to the application-defined function to be executed by the thread and represents the starting address of the thread. For more information on the thread function, see ThreadProc.
lpParameter
[in] A pointer to a variable to be passed to the thread.
dwCreationFlags
[in] The flags that control the creation of the thread. If the CREATE_SUSPENDED flag is specified, the thread is created in a suspended state, and will not run until the ResumeThread function is called. If this value is zero, the thread runs immediately after creation.Dort musst du die Adresse rein schreiben und nicht hinter dem Funktionsnamen, oder wie auch immer du das versucht hast.
-
Babelduos Geist schrieb:
hmm ich habe versucht als parameter der thread-funktion nen pointer auf nen
struct zu machen aber da kam nen fehler von wegen konnte den paramater
von CreateThread() nicht in struct koverieren.Du kanst an CreateThread jeden Zeiger übergeben. In der Thread Funktion musst Du halt den Zeiger zurückcasten.
MYStruct *p = static_cast<MYStruct *>(lpParameter);
BTW: Nimm _beginthreadex, wenn Du auch die CRT verwendest!