|
|
Hi there!
I'm having some trouble using mutexes, and since a mutex is a semaphore with only one resource, my frist idea was to use it, but it seems that or the mutex is not well implemented or i am using it in a bad manner...
For instance, if i use the following code:
<br />
CSemaphore s1(1,1,"S1")<br />
if (s1.Lock(500))<br />
{<br />
CSemaphore s2(1,1,"S1");<br />
if (s2.Lock(500))<br />
{<br />
TRACE("\n Semaphore failed!");<br />
}<br />
<br />
s1.Unlock(1);<br />
}<br />
... i never get to see the trace message in the display! But, if use:
<br />
CMutex m1(TRUE,"M1")<br />
if (m1.Lock(500))<br />
{<br />
CMutex m2(TRUE,"M1");<br />
if (m2.Lock(500))<br />
{<br />
TRACE("\n Mutex failed!");<br />
}<br />
<br />
m1.Unlock(1);<br />
}<br />
I Always see the trace message... even if i change the initial ownership of the mutex.
Can anyone, please, show me the right way to do it with mutexes?
Thanx for your time!
|
|
|
|
|
almc wrote:
and since a mutex is a semaphore with only one resource
Where did you get that idea from?
Hint: Your assumption is wrong.
|
|
|
|
|
Straight from the CreateMutex docs:
The thread that owns a mutex can specify the same mutex in repeated wait function calls without blocking its execution. Typically, you would not wait repeatedly for the same mutex, but this mechanism prevents a thread from deadlocking itself while waiting for a mutex that it already owns. However, to release its ownership, the thread must call ReleaseMutex once for each time that the mutex satisfied a wait.
|
|
|
|
|
sigh.. ok.. another problem I don't seem to understand..
sorry.. I'm a little new to MFC and Win Programming..
Ok.. I'm trying to follow along in this book "Microsoft Visual C++ Fith Edition" to create multiple views
Now the example from the book (Ex20c) compiles and works fine.. but when I try to re-create it.. I get 3 errors when I compile
error C2143: syntax error : missing ';' before '*'
error C2501: 'CMVSampleDoc' : missing storage-class or type specifiers
error C2501: 'GetDocument' : missing storage-class or type specifiers
I get these errors when I add the View Header files to the MainFrame implementation file (CMainFrm.cpp)
I can not for the life of me figure out why I am getting these error messages.. The first error message relates to the GetDocument() function in the view.
I tried two different ways.. first I used ClassWizard to create a new class derived from CView.. and I got these errors.. so I did it exactly the way the book did it.. and just copied the .h and .cpp file to new names, and modified them with different names.. thinking that maybe because the second view was avalible from ClassWizard that funked something up.. but I still receive the errors.
Any Ideas?
|
|
|
|
|
wtf ?!?
It appears that I only get errors when I try to have a View derived from CListView..
I successfully got the code to work with two CViews.. and a CView and CHTMLView.
|
|
|
|
|
Try to include the document class header in the view header. I got a similar problem before and solved it that way.
#include "MVSampleDoc.h"
.
.
.
|
|
|
|
|
Sir....I am facing one serious problem of memory leakage. I have developed one dialog based application. In that I have made one class named "CListener" derived from CWinThread. In the InitInstance() function of that class, I have added functionality which I want to perform in separate thread. From the dialog class's OnInitDialog() function I have made the following function call to run the thread.
AfxBeginThread(RUNTIME_CLASS(CListener));
All are working fine.....But when I close application Visual C++ IDE show me some memory leackage.....
Whould you please show me the way to escap from this problem....
C.R.Naik
|
|
|
|
|
How are you closing the thread? If you start the thread and close the app while the thread is still running you will get a memory leak.. In UI Threads I try to have the thread terminate it's self.. with a PostQuitMessage(0).
Rob
|
|
|
|
|
I have a Cdialog with a CListCtrl in it that sizes along with the CDialog(MoveWindow). Theres text in the list, plus scrollbars. Whne the user lengthens the CDialog, the scrollbars eventaully vanish. AT this point I want the window to not be able to lengthen any further. How do I find out when the scrollbars have disappeared. I didnt see anything like BOOL ScrollBARsExist() or something like it in MSDN...maybe I need to get the height of the text in the cListctrl but how do I figure out that?
Also theres no OnGEtMinMAxInfo for a CDialog...so what tells it to have a max limit?
|
|
|
|
|
override ::OnSizing(...)
(don't forget to add the ON_WM_SIZING() handler in your message map).
|
|
|
|
|
Thanks! Any hints about detecting the vanishing of the clistctrl scrollbars?
|
|
|
|
|
compare GetScrollPos() and GetScrollLimit().
|
|
|
|
|
WM_GETMINMAXINFO certainly works for dialogs, although it might not appear in the ClassWizard so you'll need to add the message map entries yourself.
--Mike--
The Internet is a place where absolutely nothing happens.
-- Strong Bad
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
i use courier new or verdana size 9
|
|
|
|
|
I use miriam fixed in .NET and lucida console in VS 6. They are harder to read than courier new, but the lines are closer together so I get more on the screen at a time.
|
|
|
|
|
Hmm.. As usual something that has first appeared obvious to me.. isn't.
I am using a class that sends the view a User Defined Message to notify it of some events that are taking place.
However after setting up the command handlers for the view I realized that the view was not recieving or processing the message.. so I decided to setup a test message.. and it is not working either.. so I must be doing something wrong.. and I just can't figure it out. I setup the test message handler as such.
afx_msg void OnTestMsg(WPARAM wParam, LPARAM lParam);
ON_COMMAND(WM_TESTMSG, OnTestMsg)
void CMyView::OnTestMsg(WPARAM wParam, LPARAM lParam)
{
TRACE("Test Message");
}
defined message in view header as such
#define WM_TESTMSG WM_USER + 5
Created a command ID with the following
SendMessage(WM_TESTMSG);
SendMessage(WM_TESTMSG,0,0);
::SendMessage(GetSafeHwnd(), WM_TESTMSG);
::SendMessage(GetSafeHwnd(), WM_TESTMSG,0,0);
but the message function is never fired..
Anybody see anything obvious that I am doing wrong.
Thank you.
|
|
|
|
|
ON_COMMAND is not used for handling user defined messages. For user define messages you should rather use the macro ON_MESSAGE .
In addition, the handler function for user defined messages, or that should be passed for ON_MESSAGE macro takes the follwing form:
LRESULT OnTestMsg(WPARAM wParam, LPARAM lParam);
Therefore, your code should be like this
#define WM_TESTMSG WM_USER + 5
.
afx_msg LRESULT OnTestMsg(WPARAM wParam, LPARAM lParam);
ON_MESSAGE(WM_TESTMSG, OnTestMsg)
.
.
.
LRESULT CMyView::OnTestMsg(WPARAM wParam, LPARAM lParam)
{
TRACE("Test Message");
}
.
.
.
SendMessage(WM_TESTMSG);
|
|
|
|
|
LOL... Thank you.. first simple solution I have ran across.
Thank you very much for your help
|
|
|
|
|
what code or function can i use to display the files in a directory in a console( but only the file names, none of the detailed stuff like is shown in DIR) and is it possible to transfer a variable in my C++ program to DOS, like if i told them to input the name of the file they want to open, but it needs to be compatable with up to 900 files in the folder(so i can't use switch() ) thanks, not sure if this can be done though
|
|
|
|
|
write your own code to list the files. use FindFirstFile/FindNextFile.
-c
When history comes, it always takes you by surprise.
|
|
|
|
|
moraalg wrote:
what code or function can i use to display the files in a directory in a console( but only the file names, none of the detailed stuff like is shown in DIR)
Have you tried to, at a command prompt, type
dir /?
?
If you had, you should probably have seen a switch "/B". If not, you are using an older OS that won't support this, and have to FindFirstFile&co yourself.
is it possible to transfer a variable in my C++ program to DOS
To DOS?! Are you really sure you are using VC1.52c and really sure you want to "transfer" it to dos???
like if i told them to input the name of the file they want to open, but it needs to be compatable with up to 900 files in the folder(so i can't use switch() )
Um, you want a user to be able to type in from 1 to 900 (!) filenames that you are then to operate on (not that I see how this has anything to do with sending stuff to DOS)?
If you really want the users to type this stuff in, one filename at a time, use cin. If you on the other hand can accept (the more reasonable) argv/argc way of handling this, just loop over argv and "do your thing".
|
|
|
|
|
Hi,
Has anybody had to to sort the contents of a list control by double clicking on the column header? if so pls tell me how to do the same.
Aravindan Premkumar
|
|
|
|
|
There are several solutions. One solution is to remove all items and insert new items in sorted order.
As for the column header, add a handler.
Kuphryn
|
|
|
|
|
Hi kuphryn,
I did that mate. i added a handler for mouse double click but the that traps only the double click on the list control items and not the header. do you know why is that?
|
|
|
|