|
When you're using MFC for developing applications, you should use AfxBeginThread() due to internal things in the framework that need to be set up correctly.
::CreateThread() is the Platform SDK version version when building applications with C++ without MFC support.
At last a little hint, pasted from MSDN:
A thread that uses functions from the C run-time libraries should use the beginthread and endthread C run-time functions for thread management rather than CreateThread and ExitThread. Failure to do so results in small memory leaks when ExitThread is called.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Roger Stoltz wrote: should use the beginthread and endthread
You should use beginthreadex() as it gives you more control, and endthreadex() as endthread() is fundamentally flawed.
modified on Tuesday, December 9, 2008 4:45 AM
|
|
|
|
|
Defenestration wrote: You should use beginthreadex() as it gives you more control, and endthreadex() as endthread() is fundamentally flawed.
As I wrote, this was a quote from MSDN as a hint when using Kernel32.dll from other languages than C/C++ and a different calling convention is used.
Regarding the use of any of the functions for "ending" a thread, neither of them should be used. You should simply return from the thread controlling function and if that turns out to be a problem, the design should be corrected.
Regarding beginthreadex() , you may use it unless you're building an MFC application. The only correct option is to use AfxBeginThread() when building with MFC support. This is not a matter of opinion.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Roger Stoltz wrote: Regarding the use of any of the functions for "ending" a thread, neither of them should be used. You should simply return from the thread controlling function
Indeed, and the only bulletproof method for knowing when a thread has finished, is to Wait...() on the thread handle.
|
|
|
|
|
Hi All
i want to write log file in .csv file.I am useing this code
[code]
CString strLine;
TRY
{
CStdioFile file(_T("\\mytestfile.CSV"), CFile::modeWrite|CFile::modeCreate);
file.Seek(0,CFile::end);
file.WriteString(tim.Trim());
file.WriteString("\n");
file.Close();
}
CATCH(CFileException, e)
{
e->ReportError();
}
END_CATCH
[/code]
But when new values(tim.Trim()) is come then old values auto delete.But i want to store all valuse in .csv file.Plz help me
|
|
|
|
|
I am not sure I understood your problem but you call this code several times and only the last value is saved to your file. Is that your problem ? If yes, then you need to use the CFile::modeNoTruncate flag (see here[^]). But doing that you will never erase your file (so, each time values will be appended to your file). A better approach would be to open the file only once, write all your values then close the file.
|
|
|
|
|
MsmVc wrote: CStdioFile file(_T("\\mytestfile.CSV"), CFile::modeWrite|CFile::modeCreate);
add CFile::modeNoTruncate..
MsmVc wrote: file.Seek(0,CFile::end);
you can also use existing member function SeekToEnd
I hope it helps.
Regards,
Sandip.
|
|
|
|
|
Thanks SandipG.
Just i was forget to use CFile::modeNoTruncate.
|
|
|
|
|
MsmVc wrote: file.WriteString(tim.Trim());
What is tim ?
MsmVc wrote: CString strLine;
Why is strLine never used?
What *exactly* do you want? Are you executing this code in a loop?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
I have a MFC project in Visual Studio 2008 and I want to create an installer for that application using Set up and Deployment Project option of VS2008.
I could build the basic installer which creates a desktop shortcut, makes a registry entry. But the real problem for me is check for some pre-requisites(not for .NET framework, but rather check for some application if they are already installed, say Internet Explorer 7.0 etc). If the condition is not met, I 1st would like to install that application first from my local disk or if possible bundle that with installer itself and proceed with installation of my application for which I am facing the problem.
I tried with for launch conditions-> Search for file. But the problem is as long as installation URL for the pre-requisite application is correct, that application is installed even if the Search For File Condition . But my own application doesn’t get installed. My application’s Installation halts after that dependent application is installed. Even tried to fix this problem with Solution Explorer->Project (Installer) Properties-> Prerequisites . But Prerequisites lets us check for only .NET frame work. I tried to fix this problem with Download Prerequisites from location same as my application and placed my Prerequisites application in the same folder as my project. But even then my applications own installer doesn’t proceed after Prerequisites application is installed.
Also I wanted to know if I can pass some macros while building the Installer Project.
Can you suggest me how do I go about it?
|
|
|
|
|
Hai !
We can change the Baud rate, Parity, DataBits, StopBits etc of a COM port using the Structure of DCB
DCB dcbObj;
dcbObj.BaudRate = 115200;
dcbObj.ByteSize = 8;
...
Now in order to set these changes to our port i use the Function
SetCommState (ComPortHandle, &dcbObj);
But some cobinations fail, the error message is "The parameter is incorrect", Why is it so? I get the error using GetLastError ()
Some of the Fail Combinations are :
read as
(BaudRate, Parity, ByteSize, StopBits)
(600, ODD, 7, 1.5)
(1200, NONE, 8, 1.5)
(1200, MARK, 5, 2)
etc.
Thanks !
|
|
|
|
|
kapardhi wrote: But some cobinations fail, the error message is "The parameter is incorrect", Why is it so?
Do you begin with reading the current setup with a call to ::GetCommState() ?
If not, you should in order to get your DCB struct correctly initialized. Afterwards you can easily alter the settings you need to and then call ::SetCommState() .
[edit]
However, MSDN also states that:
The use of 5 data bits with 2 stop bits is an invalid combination, as is 6, 7, or 8 data bits with 1.5 stop bits.
[/edit]
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Is this safe ?
int iOffset = 192;<br />
LARGE_INTEGER liOffset = { static_cast<LONGLONG>(iOffset) };
or should the following be used instead ?
int iOffset = 192;<br />
LARGE_INTEGER liOffset;<br />
liOffset.QuadPart = static_cast<LONGLONG>(iOffset);
|
|
|
|
|
I need to connect to MS Excel database on windows XP from winCE device
This metabase property specifies the percentage of CPU time, in 1/1000ths of a percent, that all isolated processes on the Web server can occupy during a given process accounting interval (specified by CpuResetInterval). If the processes attempt to occupy more CPU time than specified in CpuLimitPriority, all processes for that server will be set to Idle Class priority until the next process accounting reset. Any new processes on that server will also be set to Idle Class priority. Any limit over
|
|
|
|
|
When programming in C++, do you always put :: in front of every Windows API call to indicate it's in the global namespace, or you you think this makes the code ugly ?
|
|
|
|
|
Defenestration wrote: do you always put :: in front of every Windows API
No.
Defenestration wrote: indicate it's in the global namespace, or you you think this makes the code ugly ?
But why the hell do you want to use the API's in Global Namespace?
Is there some specific API that you are talking about?
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
_AnShUmAn_ wrote: Is there some specific API that you are talking about?
Any of the Windows API functions.
_AnShUmAn_ wrote: But why the hell do you want to use the API's in Global Namespace?
Suppose you have a class which has a member function with the same signature as one of the Windows API functions. If you call this function, without the :: in front, from within one of the class member functions, it will call the class member function instead of the Windows API function. Putting :: in front, causes the Windows API function to be called. So, unless you mean to call the member function, you should really put :: in front of all Windows API functions to ensure they get called.
Admittedly, it's unlikely you'll create a member function with the same name and signature as a Windows API function, but it's possible.
|
|
|
|
|
Defenestration wrote: So, unless you mean to call the member function, you should really put :: in front of all Windows API functions to ensure they get called.
Yes, other wise the compiler won't be able to figure out which function do you want to call.
Defenestration wrote:
Admittedly, it's unlikely you'll create a member function with the same name and signature as a Windows API function, but it's possible.
Yes. But then you can certainly change the member function name to something else by prefixing or suffixing it.
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
The problem with not putting the :: in front of Win API's when calling them is that you could introduce a subtle bug; the code would compile OK with you thinking your code was calling the Win API, but instead would actually be calling the member function by mistake.
|
|
|
|
|
Defenestration wrote: with you thinking your code was calling the Win API
no, a developer should take care which version should be called, the global one or the other one in the class and should use :: accordingly
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Thanks for helping me to think it through. In summary then:
:: only needs to be placed in front of Win API functions when they are called from within class member functions, otherwise it's not necessary (ie. when calling a Win API function outside of a class).
modified on Tuesday, December 9, 2008 2:41 AM
|
|
|
|
|
If you need to call the function declared in global namespace, then use the scope resolution operator, suffixing the API. If you don't do this, the local version of the API will be called.
For example, when you write an MFC app, something like MessageBox is provided to you by both - the MFC application framework and is as well available in the global namespace. A call to MessageBox will end up calling the one provided by the application framework, whereas ::MessageBox will call the one in the global namespace.
There's nothing special to it, just used to specify the scope of the API being called.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Defenestration wrote: When programming in C++, do you always put :: in front of every Windows API call
Yes.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
How about C and C++ standard library function calls ?
|
|
|
|
|
The scope resolution operator is C++ specific, thus you cannot use it in C.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|