|
It will execute 'Some operations' if m_hFunThread is signaled. If m_hFunThread is not signaled, then WaitForSingleObject will return WAIT_TIMEOUT and the program will continue after the while block.
This seems like an ..unusual thing to do.
Ryan
|
|
|
|
|
From your last question, I think you want to do
while(WaitForSingleObject(m_hFunThread, 0) != WAIT_OBJECT_0)
{
} What operations do you need to do while you're waiting? If you're just waiting and don't actually need to do anything while you wait, then use
WaitForSingleObject(m_hFunThread, INFINITE); to wait until the object is signalled.
Hope this helps,
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
My project is a sub-project. The main project controls my project.
It will call a function(OnClose())When requiring to stop my project.
Herein there exists a problem.
If the main project breaks down my project.
Something wrong will happen considering to one of my functions being running.
So I want to pop up a dialog to warn the user.
If the user still want to stop the project no matter whatever will happen, I will stop my running function,
else I will keep my function going on and let the following block not to be executed until that function has been run out.
|
|
|
|
|
OK. In that case, my first suggestion should work
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
But my entire programme was stopped.
Maybe the first parameter is wrong.
Can you tell me what kind of parameter can be used as the first?
My main dialog in my project call the riskful operation, which is a memeber function of my self-defined class.
"m_hFunThread" is one memeber of my main dialog's base class, and it should be a single thread, so my entire programme stopped.
But,every main function in my project is called by using multiple-thread way
What should I do?
|
|
|
|
|
Aleon666 wrote:
But my entire programme was stopped.
What did the WaitForSingleObject() function return? Did it return WAIT_TIMEOUT? You might want to change it from != WAIT_OBJECT_0 to == WAIT_TIMEOUT .
Aleon666 wrote:
what kind of parameter can be used as the first one?
Look at the docs for WaitForSingleObject() . There are quite a few types that can be used. I assume hFunThread is the handle to your thread. The function will return WAIT_SIGNAL_0 when the thread completes, and WAIT_TIMEOUT otherwise, unless there is an error, where WAIT_FAILED will be called.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
The main project has a release executable programme, I want to step-debug the errors, but I don't know how to DEBUG from the main project to my sub-project.
And so I don't know the returned value.
Do you know the ways?
After I displaced "!= WAIT_OBJECT_0" with "== WAIT_TIMEOUT" the programme had the same result.
As to "docs", your maening is to read some contents in MSDN, isn't it?
|
|
|
|
|
Aleon666 wrote:
Do you know the ways?
Set a breakpoint at that line and just run the entire program in the debugger. It will stop when it gets to that line.
Aleon666 wrote:
After I displaced "!= WAIT_OBJECT_0" with "== WAIT_TIMEOUT" the programme had the same result.
It stopped working at all? Hmmm. Sorry, but I think I've used up all my knowledge on multithreading I haven't done much.
Aleon666 wrote:
As to "docs", your maening is to read some contents in MSDN, isn't it?
Yeah, the information on WaitForSingleObject() . It list the handle types that support waiting for.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
The main project has nothing but an exe file and my sub-project.
I must run from the exe file.
When I run the entire program in the debugger, there is a dialog popped up, saying that "..\main.exe" does not contain debugging infomation.
Thank you very much!
|
|
|
|
|
I think out a way.
I add to a varible to control the "close" function
When the requirement is verified to stop my funtion, I stop the function directly,
else I close the dlg after my function is finished by calling "OnClose" according to the varible "m_bStopRequire".
|
|
|
|
|
I'm glad you've sorted it out
Sorry I couldn't be of more help
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
In my database date is in text format (like 20030704)
and i've to display that date in CDatetimeCtrl, after getting year month and date i am assigning that to control as follows
CTime tm(yr,mn,dd,0,0,0);
CDateTimeCtrl.SetTime( &tm );
It is showing correct in case year is above 1970, and
showing currentdate if year is 1970-
'What could be the reason and any suggesstions how to solve it??
With Thanks and Regards
--Kamesh
|
|
|
|
|
CTime doesn't support dates before Jan 1st, 1970. This is due to the C runtime library not supporting these dates in the time_t type. Use COleDateTime instead of CTime to get a greater time range.
Hope this helps,
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
If we keep on posting the same answers at the same time, I'll quit.
~RaGE();
|
|
|
|
|
Rage wrote:
If we keep on posting the same answers at the same time, I'll quit.
Don't do that!
I find that that happens a lot - I'm always posting at the same time as other people. I think it's just me
OT: I think I've got the record for the fastest reply . I posted a reply to a message last night so quickly that it showed up when the guy who posted the original message got back to the forum page after sending his message How's that for posting speed?
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
I did not check back, but if I remember well, 1970 is the lowest date you can have in a CTime. So maybe you should use a COleDateTime, which is also DateTimeCtrl compliant and which can contain any date/time.
~RaGE();
|
|
|
|
|
I'm trying to develop a cad system using MFC and OpenGL. Since I'm not an expert, can anybody explained what is the best way to do plotting.. as we know cad drawing can be very big.. most example translate the opengl drawing into DIB but this wouldn't be practical when we have big drawing as it will require huge amount of memory. Anybody got any idea ro solution maybe. or do i should thick to translating the drawing to DIB?
Thanks
p/s: sorry for my english.
|
|
|
|
|
Hi,
I have a SDI application with a listcontrol. Some fields must be in BOLD.
I have tried something with LOGFONT, but when i try to get the current logfont?, Windows gives a error at the moment that the application starts.
gxListCtrl::gxListCtrl (CString Text) <br />
{<br />
...<br />
LOGFONT lfFont;<br />
GetFont()->GetLogFont(&lfFont);<br />
Regards,
Willem
|
|
|
|
|
whofmans wrote:
Windows gives a error at the moment that the application starts
Maybe that's because you make your call to GetFont() too early, and that no font had been loaded yet. Where does the app hang when debugging ?
~RaGE();
|
|
|
|
|
GetFont() doesn't return a valid value until the control is created. The earliest you can call the GetFont() function is from the control's OnCreate() handler.
Hope this helps,
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Thanks for your help! Bold looks good.
|
|
|
|
|
I have opened a file and have a handel . Now how can i get file name back from that handel?
API GetFileInformationByHandle() returns lot of things but not file name...is there any other API that can help me out ??
thanks
|
|
|
|
|
If I remember correctly you cant in user mode, only in kernel mode.
if someone knows how to do it in kernel mode, I would very much like to know.
But if you have opened the file, then you should already have the file name.
Magnus
|
|
|
|
|
I did some research and found a way of doing it with a kernel call from user mode. Code below.
I would like to thank Felix Kasza as its his code to enumerate NTFS streams that I adapted to get the file name instead.
This is the actual code, that I have tested and it works on Win2000 Pro with .NET 2003. The filename you recive is in UNICODE. And this code have no error handling or cleanup. Thats left as an exercise for the reader
void Test()
{
NQIF nqif = NULL;
HMODULE hNtdll = LoadLibrary( "ntdll.dll" );
if ( hNtdll < (HINSTANCE) 33 )
{
return;
}
nqif = (NQIF) GetProcAddress( hNtdll, "ZwQueryInformationFile" );
if ( nqif == NULL )
{
FreeLibrary( hNtdll );
return;
}
HANDLE h = ::CreateFile( "D:\\series.txt", GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
DWORD rc;
IO_STATUS_BLOCK iosb;
FILE_NAME_INFORMATION* fni;
void* pMem = new char[1024];
fni = (FILE_NAME_INFORMATION*)pMem;
fni->FileNameLength = 1000;
rc = nqif( h, &iosb, fni, 1024, FileNameInformation );
if ( rc != 0 )
{
return;
}
fni->FileName[ fni->FileNameLength / 2 ] = L'\0';
}
You also need the following defs if you dont have the DDK.
typedef LONG NTSTATUS;
typedef struct _IO_STATUS_BLOCK {
union {
NTSTATUS Status;
PVOID Pointer;
};
ULONG_PTR Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
typedef enum _FILE_INFORMATION_CLASS {
FileDirectoryInformation = 1,
FileFullDirectoryInformation,
FileBothDirectoryInformation,
FileBasicInformation,
FileStandardInformation,
FileInternalInformation,
FileEaInformation,
FileAccessInformation,
FileNameInformation,
FileRenameInformation,
FileLinkInformation,
FileNamesInformation,
FileDispositionInformation,
FilePositionInformation,
FileFullEaInformation,
FileModeInformation,
FileAlignmentInformation,
FileAllInformation,
FileAllocationInformation,
FileEndOfFileInformation,
FileAlternateNameInformation,
FileStreamInformation,
FilePipeInformation,
FilePipeLocalInformation,
FilePipeRemoteInformation,
FileMailslotQueryInformation,
FileMailslotSetInformation,
FileCompressionInformation,
FileObjectIdInformation,
FileCompletionInformation,
FileMoveClusterInformation,
FileQuotaInformation,
FileReparsePointInformation,
FileNetworkOpenInformation,
FileAttributeTagInformation,
FileTrackingInformation,
FileMaximumInformation
} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
NTSYSAPI
NTSTATUS
NTAPI
ZwQueryInformationFile(
IN HANDLE FileHandle,
OUT PIO_STATUS_BLOCK IoStatusBlock,
OUT PVOID FileInformation,
IN ULONG Length,
IN FILE_INFORMATION_CLASS FileInformationClass
);
typedef struct _FILE_NAME_INFORMATION {
ULONG FileNameLength;
WCHAR FileName[1];
} FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;
typedef DWORD (__stdcall *NQIF)(
IN HANDLE FileHandle,
OUT PIO_STATUS_BLOCK IoStatusBlock,
OUT PVOID FileInformation,
IN ULONG Length,
IN FILE_INFORMATION_CLASS FileInformationClass
);
|
|
|
|
|
Well done! The only "problem" (as you probably realise) is that it only works on Win2k or later. FileNameInformation is not supported under NT4 or earlier (well, it's not in the NT4 DDK anyway )
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|