Click here to Skip to main content
15,897,968 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Anyone used the CShareLockNH Methods documented in MSDN Pin
Blake Miller25-Sep-08 7:47
Blake Miller25-Sep-08 7:47 
QuestionC++ heap allocation question Pin
KellyR24-Sep-08 10:57
KellyR24-Sep-08 10:57 
AnswerRe: C++ heap allocation question Pin
Mark Salsbery24-Sep-08 11:12
Mark Salsbery24-Sep-08 11:12 
AnswerRe: C++ heap allocation question Pin
Joe Woodbury24-Sep-08 11:51
professionalJoe Woodbury24-Sep-08 11:51 
GeneralRe: C++ heap allocation question Pin
Mark Salsbery24-Sep-08 11:56
Mark Salsbery24-Sep-08 11:56 
GeneralRe: C++ heap allocation question Pin
Joe Woodbury24-Sep-08 11:58
professionalJoe Woodbury24-Sep-08 11:58 
QuestionLibtorrent Pin
Pwnagedo24-Sep-08 10:29
Pwnagedo24-Sep-08 10:29 
QuestionThreads and Memory Allocation Pin
Ylno24-Sep-08 8:10
Ylno24-Sep-08 8:10 
Hello,

This is my first attempt at using threads so go easy. Could some one look at the code below and tell me if I'm going to run into trouble if I keep calling this function i.e. loss of memory.

The reason why I'm trying to use a Thread is this: we are writing .dll files to add functionality to a scripting language which is used in a software. The problem is that when a c++ function is called from a .dll file from within this scripting language the next line of code (in the script) doesn't get called until the .dll's function has returned. I was thinking that I could use a thread to get around this problem.
Does this make sense? or is there another way of doing it?
Thanks

#include <iostream> 
#include <windows.h>
using namespace std;


typedef struct PulseData {
	int iData1;
	int iData2;
} DATA, *PDATA;

DWORD WINAPI TestFunction(LPVOID lpParam){
	PDATA pPassedData = (PDATA)lpParam;
	Sleep(1);
	cout << pPassedData->iData1 << endl;
	cout << pPassedData->iData2 << endl;
	Sleep(1);
	return 0;
}

int main(){
	PDATA	pPulseData[1];
	DWORD	dwThread[1];
	HANDLE	hThread[1];
	// Allocate memory for thread
	pPulseData[0] = (PDATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DATA));
	
	pPulseData[0]->iData1 = 100;
	pPulseData[0]->iData2 = 200;

	cout << "creating thread" << endl;
	hThread[0] = CreateThread(NULL, 0,TestFunction, pPulseData, 0, &dwThread[0]);
	cout << "thread finished" << endl;

	system("PAUSE");
	return 0;
}
</windows.h></iostream>


p.s. the includes are:
#include <iostream>
#include <windows.h>
I don't know why they don't show up in the code
GeneralRe: Threads and Memory Allocation Pin
Perspx24-Sep-08 8:32
Perspx24-Sep-08 8:32 
AnswerRe: Threads and Memory Allocation Pin
Mark Salsbery24-Sep-08 9:37
Mark Salsbery24-Sep-08 9:37 
GeneralRe: Threads and Memory Allocation Pin
Ylno24-Sep-08 10:30
Ylno24-Sep-08 10:30 
GeneralRe: Threads and Memory Allocation Pin
Mark Salsbery24-Sep-08 10:49
Mark Salsbery24-Sep-08 10:49 
GeneralRe: Threads and Memory Allocation Pin
Ylno24-Sep-08 11:23
Ylno24-Sep-08 11:23 
AnswerRe: Threads and Memory Allocation Pin
Ylno24-Sep-08 11:48
Ylno24-Sep-08 11:48 
GeneralRe: Threads and Memory Allocation Pin
Mark Salsbery24-Sep-08 11:58
Mark Salsbery24-Sep-08 11:58 
GeneralRe: Threads and Memory Allocation Pin
Ylno24-Sep-08 12:22
Ylno24-Sep-08 12:22 
GeneralRe: Threads and Memory Allocation Pin
Mark Salsbery24-Sep-08 13:17
Mark Salsbery24-Sep-08 13:17 
QuestionMatrix to transform a vector MA to MB Pin
ybenaabud24-Sep-08 8:09
ybenaabud24-Sep-08 8:09 
AnswerRe: Matrix to transform a vector MA to MB Pin
CPallini24-Sep-08 8:34
mveCPallini24-Sep-08 8:34 
GeneralRe: Matrix to transform a vector MA to MB Pin
ybenaabud24-Sep-08 13:41
ybenaabud24-Sep-08 13:41 
GeneralRe: Matrix to transform a vector MA to MB Pin
ybenaabud24-Sep-08 13:46
ybenaabud24-Sep-08 13:46 
GeneralRe: Matrix to transform a vector MA to MB Pin
CPallini24-Sep-08 22:52
mveCPallini24-Sep-08 22:52 
GeneralRe: Matrix to transform a vector MA to MB Pin
ybenaabud25-Sep-08 11:35
ybenaabud25-Sep-08 11:35 
GeneralRe: Matrix to transform a vector MA to MB Pin
Rajesh R Subramanian28-Sep-08 19:32
professionalRajesh R Subramanian28-Sep-08 19:32 
GeneralRe: Matrix to transform a vector MA to MB Pin
CPallini28-Sep-08 21:50
mveCPallini28-Sep-08 21:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.