|
Thank you for all of you.
I included test.h but it doesn't work as well But it works when I declare it as external inside XX.cpp so its now work fine.
Really you save my time with your experince and many thanks.
Regards.
|
|
|
|
|
You are welcome.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi
I come back to make updating on this function to make the initialization for these variables through function and this function should bring the values from DB.
I am struggling with where I should declare the function and where I could call this function to be luncing once the MFC dialog interface launched. I tried many ways but always the compiler inform me that "unresolved external symbol" for the used external variables.
I tried to put the function declaration as a member function in the testApp class //but failed
I tried to put the function declaration as a member function in the ZZ.cpp and make the proper including //but failed and inform me that you can't initialize them into closed scope.
it seems to me that the initialization should be in the test.cpp and without function using. I don't believe that but how I can make it.
Any help will be appreciated
|
|
|
|
|
Hello,
I just played around with mutexes and wrote the following piece of code:
HANDLE hMutex = CreateMutex(NULL,
TRUE,
"test");
DWORD err = WaitForSingleObject(hMutex, INFINITE);
if( err == WAIT_FAILED )
printf( "This shouldn´t happen." );
else
{
err = WaitForSingleObject(hMutex, INFINITE);
if( err == WAIT_FAILED )
printf( "This shouldn´t happen." );
else
printf( "This shouldn´t happen either." );
}
No I don´t understand why the second WaitForSingleObject()-call doesn´t block. Since I said to wait indefinitely, shouldn´t it do so because the mutex object is already in use?
I guess, I have some general trouble understanding the mechanism here. How do I get the mutex to lock a code area up?
Souldrift
|
|
|
|
|
Whay don't you use GetLastError() when the return value is WAIT_FAILED as the documentation suggests?
|
|
|
|
|
There is no error. The return value both times is 0. Which is fine with the first call, and I thought was odd with the second.
But I just read somewhere else, that mutexes under windows don´t block inside the same thread. So that might be it.
Souldrift
|
|
|
|
|
Souldrift wrote: No I don´t understand why the second WaitForSingleObject()-call doesn´t block. Since I said to wait indefinitely, shouldn´t it do so because the mutex object is already in use?
Souldrift wrote: I guess, I have some general trouble understanding the mechanism here.
You're missing this ([^])
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.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yes, that was exactly it. Just found out a minute ago.
Thanks a lot. Just tested it with threads and it seems to work allright .
Good day all.
Souldrift
|
|
|
|
|
Hi, I've been using code project for a few years now. This is my second account after a while away (forgot my login details).
Anyway, I just have a small question. Does anyone know of a style flag that will stop my window being palced on the taskbar. I have found the shellnotify code for the systray stuff i want to do, I just don't seem to be able to remove it from the bar.
I've looked on the msdn website and all i can find is not to use WS_EX_APPWINDOW, but even when i remove it my window is still in te task bar.
Any help would be excellent! Thank you,
Nicola.
|
|
|
|
|
Actually very simple!
You just need to use a flag which creates an unowned window without placing it on the task bar. For this use: WS_EX_TOOLWINDOW.
|
|
|
|
|
Don't they call this 'self-sercice'?
|
|
|
|
|
I'm THAT good.
|
|
|
|
|
Hi,
I am using visual studio 2008, C++ MFC for window xp. I have a program that will create some files in my directory (like in C:/) which i created earlier and it will read/write data into the files. As the date is quite big, it take quite a while to write/read. So i would like to know is there anyway to prevent other from accessing to my files (go into C:/ and open it) when my program is running (writing or reading the files)? I am using fopen for file open and fscanf to read. Thanks alot.
|
|
|
|
|
Use the OpenFile API ([^]) with uStyle as OF_SHARE_EXCLUSIVE.
Opens a file with exclusive mode, and denies both read/write access to other processes. If a file has been opened in any other mode for read/write access, even by the current process, the function fails.
Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks. I will try it out now. Thanks alot
|
|
|
|
|
Hi ARJ 09,
I would liek to know how to use OFSTRUCT? Thanks
Can give me a example?
the one i am using now is like this
FILE f3;
Cstring a = "C:/abc12";
f3 = fopen(a, "w");
fscanf(f3, "%d%d\n", &b, &c);
Please help me out. Thanks
|
|
|
|
|
In OpenFile, OFSTRUCT is a output parameter, that returns the opened file attributes.
LPCSTR lpFileName = "c:\sample.txt";
OFSTRUCT ReOpenBuff ;
HFILE hFileHandle;
hFileHandle = OpenFile(lpFileName,&ReOpenBuff,OF_SHARE_EXCLUSIVE );
Величие не Бога может быть недооценена.
|
|
|
|
|
|
Hi ARJ09,
is there a way to put/asign the OpenFile to another file name. Like
FILE* f;
f = OpenFile(.......);
Cos i need the f for fscanf
fscanf(f, "....", &a,&b);
|
|
|
|
|
Nicholas Amh wrote: is there a way to put/asign the OpenFile to another file name.
Yes, just use a different name. You should read up on the use of variable names in C++.
|
|
|
|
|
OpenFile returns HFILE, so using FILE* is not good.
and aviod fscanf.
Even OpenFile is not good in 32 bit application, the better approach is CreateFile([^]) which returns HANDLE.
Величие не Бога может быть недооценена.
|
|
|
|
|
Do anyone know the code for displaying the selected items and its child items of a treecntrl into a listcntrl?
|
|
|
|
|
Well Tree and List View control have methods (if you're using MFC ) or messages you can exploit (You're a developer, right?)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am a fresher in MFC. That is why asking such questions.
|
|
|
|
|
Have a look at documentation, see, for instance, "using CTreeCtrl " [^] and "using CListCtrl " [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|