Click here to Skip to main content
15,894,646 members
Articles / Desktop Programming / ATL

Using CAtlArray for a class member variable

Rate me:
Please Sign up or sign in to vote.
3.67/5 (12 votes)
6 Oct 2012CPOL 0   13  
[ bappycse05] is correct but I also used a Thread which is a member function of a class and wanted it to access the class's member variables, but the moment the thread ends, any changes it makes in any member variables are erased.

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
6 Oct 2012Briti Sundar
May be you have missed to malloc first before insert into MyArray.MyDataStructure* pNewStruct;pNewStruct =(MyDataStructure* )malloc(sizeof(MyDataStructure));MyArray.Add(pNewStruct);Hope this will work.
Please Sign up or sign in to vote.
8 Oct 2012Briti Sundar
This work for me and i get value after thread exit. Compare your code with me , you can understand your problem. Another thing CreateThread can not call a member function, so you must need a static function for this.,#include "stdafx.h"#include #include #include #include class...
Please Sign up or sign in to vote.
6 Oct 2012Michael Haephrati 7 alternatives  
I would appreciate it if someone can provide me with a code sample for using CAtlArray as a member variable inside a class, where the array should hold a custom data structure.I have defined the data structure:typedef struct{ int Status; CTime StatusDate;}...
Please Sign up or sign in to vote.
9 Oct 2012Michael Haephrati
How can I get notified, to the main even loop when this thread completes?
Please Sign up or sign in to vote.
8 Oct 2012Michael Haephrati
Something like// testproject.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include #include typedef struct{ CString FullPath; CTime StatusDate;} Item;class MyClass{public: MyClass(); ~MyClass(); void...
Please Sign up or sign in to vote.
8 Oct 2012Briti Sundar
It will be better if you post a little bit of code. However,suppose classname is MyClass and your thread name MyThread. You call this thread from your class. then try this.._beginthread(MyThread,0,this);void* MyThread(void* arg){ MyClass* newObj = (MyClass* )arg; // now...
Please Sign up or sign in to vote.
9 Oct 2012Briti Sundar
Use this ---dwRet = WaitForSingleObject(HANDLE,TIME);see the example .. http://www.installsetupconfig.com/win32programming/threadprocesssynchronizationapis11_13.html[^]when thread will be completed, use postmessage method to inform UI :D

License

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


Written By
CEO Secured Globe, Inc.
United States United States
Michael Haephrati is a music composer, an inventor and an expert specializes in software development and information security, who has built a unique perspective which combines technology and the end user experience. He is the author of a the book Learning C++ , which teaches C++ 20, and was published in August 2022.

He is the CEO of Secured Globe, Inc., and also active at Stack Overflow.

Read our Corporate blog or read my Personal blog.





Comments and Discussions