|
In Main File
In my application on click of a button, i'l check if DB connection is there. if its not then
pApp->m_hEvent = ::CreateEvent(NULL, FALSE, FALSE, "FileEvent");
pSLMDoc->UpdateJobOrderInfo(m_pJobOrderInfo); //This fuction starts a thread to write a file.
In the thread File
CBackupFile file;
file.WriteFile(pDBJobOrder); //Calls a fuction to write a file
delete pDBJobOrder;
::SetEvent( ((CSLMApp*) AfxGetApp())->m_hEvent ); // Set the event
return;
I want to wait untill this thread executes.. but it is not happening...
Did u get my problem..
megha
|
|
|
|
|
you mean, you want to wait in the button till the thread comletes. am i right?
|
|
|
|
|
Often, if you have/want to wait for another thread to execute, you don't need another thread.
If the creating thread can't continue executing until the second thread finishes, do you
really need another thread?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
try to follow this algorithm.
int flag=0;//global variable
button code
{
pApp->m_hEvent = ::CreateEvent(NULL, FALSE,
FALSE, "FileEvent");
pSLMDoc->UpdateJobOrderInfo(m_pJobOrderInfo); //This
fuction starts a thread to write a file.
while(flag==0);//wait till flag is made 1.
}
thread code
{
//perform your writing here
then at the end of the thread, make flag=1;
}
}
|
|
|
|
|
I tried this one
It is working.
Thank u
|
|
|
|
|
If this is the solution, then what is the use of events...
- NS -
|
|
|
|
|
please rename this message subject by prefixing [solved] to the subject
thanx
|
|
|
|
|
First, as Mark said, if the initiating thread has to wait for the second thread to finish, why bother with the second thread?
To answer your question, consider this from the MSDN description of CreateEvent:
If lpName matches the name of an existing named event object, this function requests the EVENT_ALL_ACCESS access right. In this case, the bManualReset and bInitialState parameters are ignored because they have already been set by the creating process<br />
<emphasis mine>
Since I don't see a CloseHandle anywhere, I bet you're reusing the event without resetting it's state. Try adding a ResetEvent function call before starting your secondary thread. OR Switch to an unnamed event - you don't need a named event since you reach back into the app to get the event handle in your secondary thread.
Judy
|
|
|
|
|
I am using the following code (it's in MSDN)
HANDLE hFile = CreateFile(_T("C:\\MyFile.DAT"),
GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Couldn't create the file!"));
else
{
CFile myFile(hFile);
static const char sz[] = "Hockey is best!";
myFile.Write(sz, lstrlen(sz));
myFile.Close();
}
But MyFile.Dat is displaying unreadable characters.
What's the problem?
|
|
|
|
|
why dont you try the same with FILE * fp instead.
that is very convinient.
|
|
|
|
|
|
can you just send me the code snippet of that used with FILE * fp.
i can solve this problem.
|
|
|
|
|
CFile cfile_object;
cfile_object.Open( TEXT("d:\\New.txt"), CFile::modeCreate|CFile::modeWrite);
char szSampleText[100];
strcpy(szSampleText, "Sample Text for CFile Write function Example");
cfile_object.Write (szSampleText,100);
cfile_object.Close();
I got this from www.codersource.net
|
|
|
|
|
you didnt get my point DumbDude
try using the following code.
FILE *fp;
char szSampleText[100];
fp=fopen("d:\\New.txt","w");
fprintf("%s",szSampleText);
fclose(fp);
this will definately work.
|
|
|
|
|
Try
<font>CFile cfile_object;
cfile_object.Open( TEXT("d:\\New.txt"), CFile::modeCreate|CFile::modeWrite);
char szSampleText[100];
strcpy(szSampleText, "Sample Text for CFile Write function Example");
cfile_object.Write (szSampleText, <font color="Red">strlen(</font></font><font color="Red"><font><font>szSampleText</font></font></font><font><font color="Red">)</font>);
cfile_object.Close();</font>
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
DumbDude.Dll wrote: But MyFile.Dat is displaying unreadable characters.
How you view the file? I mean, you used notepad?
- NS -
|
|
|
|
|
Hello Friends,
I am using Dialog based application. And i want to know when the mouse is clicked even if the Dialog(application ) is MINIMIZED or HIDDEN.that is want to even if mouse is clicked outside the application window.
Is this possible to do so ????????.
If yes. please tell me how.
|
|
|
|
|
as far as iknow, that is not possible, because, the mouse click events are local to an application. i.e. this application cannot track the mouse, once it is out of its scope.
if you can tell the actual purpose of your requirement, i can suggest you some idea to achieve it.
|
|
|
|
|
Ofcourse... You have to use a mouse hook.
See this[^]
- NS -
|
|
|
|
|
Hi,
Am developing a CAD application using OpenGL and MFC. But the PDF output's clarity from our application is very poor. We are using DIB. Is it possible to do all using GDI as we are doing in OpenGL. And the main thing am dealing the drawing of Complex Polygons using Tessellation in OpenGL. But how to do it in GDI. And if i selected GDI, will the PDF's clarity is good? Suggestions please..
With Regards,
Sangeetha.
|
|
|
|
|
One suggestion is that you can go for EMF or WMF.
- NS -
|
|
|
|
|
Please suggest me some links regarding the EMF and WMF. My client is asking for high quality pdf output.
With Regards,
Sangeetha.
|
|
|
|
|
That is only image formats... you can find more details in MSDN itself.
- NS -
|
|
|
|
|
Hi,
If i develop using GDI, Will i could scale and pan the picture? As well as Printing with high resolution?
Can anyone tell me the ideas?
With Regards,
Sangeetha.
|
|
|
|
|
Hello everyone,
There is a ncb file under the working directory of my Visual Studio 2005 project. It is very big, almost 7M. I am wondering,
1. what is the function of this file?
2. If I want to share code with someone else remotely, could I remove this file and send only other files? (sending 7M file through slow internet connection is time consuming)
thanks in advance,
George
-- modified at 3:25 Friday 31st August, 2007
|
|
|
|