|
Hi,
following situation:
Class A owns an array of Class B variables.
Class B owns a variable of Class C.
Class C runs as a thread which is started by Class B.
What I want to do: when thread C ends, I want Class A to remove B from the array.
What I tried: B knows whom it is owned (knows the A) and C knows the B. So when C ends, it can call a function in A to tell it to remove B.
However this is a quite bad solution. Because the function can't really complete (it can't jump back into C because it has then been destroyes). It just not seems to work.
How can I code this clean?
Thanks a lot!
Chris
|
|
|
|
|
Perhaps C could remove its entry from A 's array of class B variables just before it terminated?
<edit>
If you're implementing a thread pool, you might want to see this[^] article if you haven't already.
</edit>
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
hello all.
as far as i know, a CRecordView class requires a dialog resource. i tried the sample enroll in msdn.i have a SDI now what i want to happen is that when i clik on a menu item( lets say in menu TOOLS-->records)so when i clik records i need that the recordview object(CSectionForm for eg) must open in a new window.(in the samples it opens in the main window client area only).many advised me that perform a dialog.domodal on the clik event ..but that opens up a dialog box.. and dialog box doesnt allow me to take a CRecordView...other way round, the CRecordView doesnt take a dialog resource already tied to CDialog....hope u all understand what i want...
please help me out quickly ...
i have my proj submission on wednesday.. be quick please
can mail me on badbady_2000@yahoo.com too...
pls be fast.
thank u
love u all
|
|
|
|
|
Hi,
Is there a way of getting the current users profile directory. I am wanting to store some files in ApplicationData.
Thanks
Mark
|
|
|
|
|
See GetUserProfileDirectory() and SHGetFolderPath()
Mazy
"Man is different from animals in that he speculates, a high risk activity." - Edward Hoagland
|
|
|
|
|
I have the following code in my program
data.GetErrorFlag == CVerifyData::InvalidData When this code executes I get two errors on it, they are as follows, Error 1: "error C2446: '==' : no conversion from 'const long' to 'long (__thiscall CVerifyData::*)(void)'", with extra info stating "There are no conversions from integral values to pointer-to-member values". Error 2: "error C2040: '==' : 'long (__thiscall CVerifyData::*)(void)' differs in levels of indirection from 'const long'" data is a variable of type CVerifyData. The GetErrorFlag function returns a value of tye LONG and CVerifyData::InvalidData is a static member variable defined in the class header/implementatoin files as
static const LONG InvalidData;
const LONG InvalidData = 0; Could anyone give me some help on why I'm getting this error. I don't really understand what it's saying. Thanks.
- Aaron
|
|
|
|
|
|
Wow, I feel like a complete bonehead now. Thanks again for the help. Can't belive I missed that.
- Aaron
|
|
|
|
|
I have an exe. i have several COMs (0 or more) which are Dlls.
all COMs have the same one and only interface called IMgr and co-class CMgr.
in this interface there is a method called 'GetModuleDlg' which does something
all the COM-Dlls are located under the subdirectory 'Dlls'
I use the 'LoadTypeLib' and GetTypeInfoCount and GetTypeInfo
to connect to the COM-Dlls. i need to mention, i don't have the *.tlb files and all the connection is done dynamically in run-time not in compilation time.
my question is this : all i have to do is to "CreateInstance" of the COM dll, and then invoke "GetModuleDlg"....can any1 show me code on how to do that using the ITypeLib and ITypeInfo interfaces???
I've searched CP, CG and google, but i found poor examples regarding....
thanks in advanced
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
I need to define an array of CMenu's. But I really dont now how many I need, I only know this at runtime.
I cant do this... CMenu menu[myvariable];
Because it needs a constant.
When I use CMenu *menu = new CMenu[myvariable];
The program crashes when I try to access a member function of CMenu. Like, menu[0]->AppendMenu[...];
Can I not use CMenu[variable] at all? Is there no workarounds?
BTW, I dont know why it crashes when I use pointers to CMenu.
Thanks!
Daniel
|
|
|
|
|
You could use a dynamic collection (eg: CPtrArray ).
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I would use a linked list........
|
|
|
|
|
Daniel1324 wrote:
The program crashes when I try to access a member function of CMenu. Like, menu[0]->AppendMenu[...];
Forget what I first typed, it was plain wrong. However, it seems probable that your array of CMenu items needs to be initialised in some way.
Or you could use a vector, or list, depending on the metrics of how you will use the collection.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
You have to initialize each CMenu in the array via a call to CreateMenu() , something like this:
CMenu *menu_array = new CMenu[myvariable];
for (int i = 0; i < myvariable; i++) {
menu_array[i].CreateMenu();
}
Software Zen: delete this;
|
|
|
|
|
Nice n simple, and it should work
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Thanks! I tried that and it worked, but I dont understand why.
I thought that with pointers you had to use '->' instead of '.'.
I was using menu_array[i]->CreateMenu();
instead of menu_array[i].CreateMenu();
Could you shed some light on this for me?
Thanks!
|
|
|
|
|
In C and C++, an array is simply a constant pointer to the first array element. Array notation A[i] denotes the i<sup>th</sup> element of the array starting at A , and is equivalent to the pointer notation *(A + i) .
Turning this around, this means you can use a pointer as if it were an array, and this is what I did in my example. The menu_array value is a pointer to the first element in an array. Given that, menu_array[i] gives you the actual CMenu object, rather than a pointer to an object.
I realize this is rather subtle. It takes a while to get used to.
Software Zen: delete this;
|
|
|
|
|
Cool, that kinda makes sense... I'll have to think about it for a while!
Thanks!
|
|
|
|
|
Daniel1324 wrote:
When I use CMenu *menu = new CMenu[myvariable];
You declare an array of CMenu so menu[n] is a CMenu, not a *CMenu
There are plenty of other reasons why the program would crash but until you understand this first one you're not going to get very far...
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
Hi.
Is there a way to capture a char from console buffer in a Win 32 Console Application?
I know how to place the cursor on the console screen and replace something but now I wanna know how I get the char from the cursor.
|
|
|
|
|
search for Console here in CP you will many examples that does that.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Hi,
I am trying to migrate my existing code (c++ - MFC) that works fine in VS6 to VS7.
In my code i have a client server mechanism using the MFC CSocket and Carchive to serialize objects between sides.
This works fine under VS6, but when compiled and run in VS7 the actual serialization process (the storing\reading to\from the archive object) takes much much longer, and after a while it simply get stuck.
when i break in to the the code on the send side i see it is stuck in CSocket::SendChunk and every time it tries to send it gets the WSAEWOULDBLOCK.
(All of the transferred objects are CObject derived ( DECLARE_SERIAL, IMPLEMENT_SERIAL and Serialize overloaded) and contains only MFC CObject derived or CStrings composite object )
Any known issues or ideas?
|
|
|
|
|
im looking for a method,
to find out the account type
of the logged in user,
as in,
administrator or guest priveldges etc
Thanks
|
|
|
|
|
I am having a problem with threads and wonder if anybody can help,
I am spawning a worker thread that updates a linked list that I need access to from the other thread, basically i am passing the instance of the class with the linked list using a struct:
UINT CNetworkMonitoringDoc::CaptureThread(LPVOID pParam)<br />
{ <br />
THREADPARMS* ptp = (THREADPARMS*) pParam;<br />
CPacket* m_capturedPacket = ptp->pPacketInst;<br />
delete ptp;<br />
...<br />
}<br />
The worker thread adds data to the linked list ok but when the orginal thread needs to do something with the m_capturedPacket instance the contained linked list is empty, im guessing the thread is creating its own private copy and working on that; is there anyway to share m_capturedPacket between them?
Cheers
Andy
|
|
|
|
|
I solved this problem by placing a critical section around the usage of the instance of my class
|
|
|
|