|
the code looks ok, except maybe for the display method; the show_book method will do what ? no, it is declared as void , and cout will do nothing for it; or might not compile.
to find a book, you need to compare somthing, when iterating the list, you can compare one it with the search criteria.
for example ( pseudo code )
<br />
CString sCriteriaTitle;<br />
for(int i = 0; i < book_list.size(); i++)<br />
{<br />
if ( sCriteriaTitle.Compare( book_list[i]->get_book_title() ) == 0)<br />
{<br />
bFound = true;<br />
}<br />
}<br />
<br />
}<br />
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
A Class is just a structure. Can youm write a structure with all these elements?
"Naked we come and bruised we go."
- James Douglas Morrison
Best Wishes,
ez_way
|
|
|
|
|
Once upon a time there was a thread:
UINT CIrisAdqDlg::CaptureImageThread(LPVOID pParam)
{
...
}
And one day I tried to launch it:
void CIrisAdqDlg::OnStart()
{
...
AfxBeginThread(CIrisAdqDlg::CaptureImageThread, this);
...
}
But VC++ didn't want:
...
error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
...
I am sure it worked in the past, so I don't know what it's really happening now.
Thanks!
|
|
|
|
|
Hi
This occurs when you use Member functions as the parameter of AfxBeginThread.
Write the Thread function outside the class.
This http://www.codeproject.com/win32/callback_adapter.asp[^] may be of help to you.
Regards
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
Or make the member function static.
If I write code in my sleep, does that make me brilliant, or just a lazy programmer?
My articles
www.stillwaterexpress.com
BlackDice - the programmer formerly known as bdiamond
|
|
|
|
|
Hi, I have a dll that runs as a process via dllHost.
My problem is i need to know when a Windows Shutdown event is being fired. I've never had this problem before because all my apps have a main window and receive this notification. However the dll just keeps working and terminates in an undetermined state.
I can't have the dll called from an app. I have no alternative but to use what i've got.
how can i register to receive a WM_SHUTDOWN event from my dll?
Please don't suggest i change the design of the solution. I'm confined to what i have.
thanks in advance
Carl
|
|
|
|
|
What about a creating an invisible hidden window for just receiving this message (under W2K+ you can use message only windows designed specially for these purposes - see HWND_MESSAGE for details)
|
|
|
|
|
thanks for the comment but firstly this needs to be a solution to all current windows platforms (excluding servers) and secondly i'm sure there must be a way to register for this event, even in a dll. hmmm
Regards
Carl
|
|
|
|
|
Yes instead though create a custom message
In both headers:
#define MY_MESSAGE (WM_USER+22)
Then trap it in defwinpro
"Naked we come and bruised we go."
- James Douglas Morrison
Best Wishes,
ez_way
|
|
|
|
|
I only have one binary, the dll. Hence only one header. I am running the dll as an application, through another process.
|
|
|
|
|
OK sorry, did your try force parm?
BOOL x = ExitWindowsEx(EWX_FORCE,NULL);
"Naked we come and bruised we go."
- James Douglas Morrison
Best Wishes,
ez_way
|
|
|
|
|
Hi
I started a thread to check for a file change using the below code
CWinThread* m_UpdateMonitorThread = AfxBeginThread(CheckFileUpdates,(LPVOID)this)
UINT CheckFileUpdates(LPVOID lp)
{
while( ReadDirectoryChangesW(
hDir, // handle to directory
&Buffer, // read results buffer
sizeof(Buffer), // length of buffer
TRUE, // monitoring option
FILE_NOTIFY_CHANGE_SIZE, // filter conditions
&BytesReturned, // bytes returned
NULL, // overlapped buffer
NULL// completion routine
))
{
//do the work
}
}
Now on I have abutton on my UI. Onclick of the button I want to stop the above thread.
I I tried to use
if(m_UpdateMonitorThread)
{
DWORD dwRetCode;
while (!GetExitCodeThread(m_UpdateMonitorThread->m_hThread, &dwRetCode));
TerminateThread(m_UpdateMonitorThread->m_hThread,dwRetCode);
m_UpdateMonitorThread = NULL;
}
and
if(m_UpdateMonitorThread)
{
m_UpdateMonitorThread->SuspendThread();
m_UpdateMonitorThread->Delete();
m_UpdateMonitorThread = NULL;
}
I am getting memory leaks in both the above cases. I tried to post a Stop Event, but where do I wait for this event inside the thread code as execution will not go inside the while loop code because of ReadDirectoryChangesW.
Can anyone please please suggest a way out to this problem.
Thanks in anticipation of information.
Madhavi
|
|
|
|
|
TerminateThread is guaranteed to leak every sort of resources the thread might have acquired. Do not use it ever for finalizing the thread, except in extreme circumstances.
So, try setting a stop event. In order to be able to handle this event while doing the ReadDirectoryChangesW stuff, you must perform the latter in overlapped mode (check the docs for ReadDirectoryChangesW ): basically, the op is done asynchronously, and its completion is signalled through an event, so you can fire the operation and wait in one single WaitForMultipleObjects for both completion or the stopping event, whatever comes first.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Hi Joaquín
Thanks for your quick response. I am unable to use the overlapped mode. I mean I am not getting the correct usage syntax.
I simply used stop event as shown below.
UINT CheckFileUpdates(LPVOID lp)
{
//Get the document pointer
CLogViewerAppView* pView = (CLogViewerAppView*)lp;
CLogViewerAppDoc* pDoc = pView->GetDocument();
CFileException err;
CFileStatus st;
CFile::GetStatus(pView->m_LogFilePath,st);
LONG l1,l2;
CFile file;
if( !file.Open(pView->m_LogFilePath, CFile::modeRead|CFile::shareDenyNone, &err ) )
{
TCHAR szCause[255];
err.GetErrorMessage(szCause, 255);
AfxMessageBox(szCause);
return 0;
}
l1 = (LONG)file.GetLength();
file.Close();
CFile file1;
LONG size_1 = (LONG)st.m_size;
int len = pView->m_LogFilePath.GetLength()-pView->m_LogFileName.GetLength()-1;
CString dir = pView->m_LogFilePath.Left(len);
HANDLE hDir = CreateFile( dir, // pointer to the file name
FILE_LIST_DIRECTORY, // access (read/write) mode
FILE_SHARE_READ|FILE_SHARE_WRITE, // share mode
NULL, // security descriptor
OPEN_EXISTING, // how to create
FILE_FLAG_BACKUP_SEMANTICS, // file attributes
NULL // file with attributes to copy
);
FILE_NOTIFY_INFORMATION Buffer[1024];
DWORD BytesReturned;
while( ReadDirectoryChangesW(
hDir, // handle to directory
&Buffer, // read results buffer
sizeof(Buffer), // length of buffer
TRUE, // monitoring option
FILE_NOTIFY_CHANGE_SIZE, // filter conditions
&BytesReturned, // bytes returned
NULL, // overlapped buffer
NULL// completion routine
))
{
if ( WaitForSingleObject(pView->m_StopEvent, INFINITE) == WAIT_OBJECT_0 )
{
OutputDebugString(_T("\n KIIGSRETG \n"));
return 0; //end the thraed
}
CString fileName(Buffer[0].FileName);
fileName = fileName.Left(Buffer[0].FileNameLength / 2);
if(fileName.CompareNoCase(pView->m_LogFileName) == 0)
{
//Do the work
}
}
return 0;
}
But the m_StopEvent event is not caught beacuse the control is stuck at while( ReadDirectoryChangesW) I mean it not going inside the while loop unless ReadDirectoryChangesW returns true. Hence WaitForSingleObject is not checked at all.. Hope you got my point.
Can you please let me know how to write this using OVERLAPPED structure. I never did this before. I am really stuck at this point..unable to proceed further..this is very important for my assignment.
Thanks
Madhavi
|
|
|
|
|
Good Day.
Please, can you give me an example how can I change state of the button with some id? I do like this:
m_wndReBar.Create(this);
m_wndReBar.AddBar(&m_wndToolBar);
...
m_wndToolBar.SendMessage(TB_SETSTATE, ID, MAKELONG(TBSTATE_ENABLED, 0));
...
But nothing changes. What's wrong? Or what another ways exists to change the state?
Nulla dies sine linea !!!
|
|
|
|
|
And if I have a button in ReBar how can I change state of it?
Nulla dies sine linea !!!
|
|
|
|
|
To change the state of button on DialogBar I have used
for Disable
m_wndToolBar.GetDlgItem(IDC_BUTTON)->EnableWindow(FALSE);
for Enable
m_wndToolBar.GetDlgItem(IDC_BUTTON)->EnableWindow(TRUE);
For unPressed
m_wndToolBar.CheckDlgButton(IDC_BUTTON,BST_UNCHECKED);
For Pressed
m_wndToolBar.CheckDlgButton(IDC_BUTTON,BST_CHECKED);
I thing it will also work for Rebars
|
|
|
|
|
I am building an application; Along with the main SDI window it has a modeless dialog, SDI has system menu but the modeless dialog has no system menu icon; (upper left part of task bar), although I have selected system menu and taskbar options in the dialog properties.
How to add system menu / icon in a modeless dialog?
Please Help.
|
|
|
|
|
Is it a child and is that selected?
"Naked we come and bruised we go."
- James Douglas Morrison
Best Wishes,
ez_way
|
|
|
|
|
Thanks for reply;
I have created dialog in the OnCreate of CMainFrame like this;
mydlg.Create(IDD_MYDLG, this);
In the properties tab the style of dialog is POPUP not child;
making it child donot displays it.
|
|
|
|
|
Hi,
I want to execute the function for evry 3 minuts.How can I call the event multiple times in this regard?
Please help me.
dadsadasd
|
|
|
|
|
Hi
Add a event handler of WM_TIMER. Create a ID for the particulare timer, ie for 3 minutes say, IDT_TIMER1.
On the initialization part of your application call
SetTimer(IDT_TIMER1,18000,NULL);
Now call the function inside the event handler for WM_TIMER.
Check for the nIDEvent with IDT_TIMER1 if you have multiple timers in your application.
Hope this would help you
Regards
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
zainu wrote:
SetTimer(IDT_TIMER1,18000,NULL);
You might want to change that to 180000.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
It's possible set a file dialog (CFileDialog) to let select to user only directories?
I want to do this to choose the work directory of my software.
Somebody can help me?
Thanks a lot
|
|
|
|
|