|
gabbana wrote: I hope everybody understand whats my problem. Thank you for help.
For instance I cannot understand your problem.
To get the text of an edit box, using Windows API , you may to call GetWindowText this way
TCHAR szBuf[0x100];
if (! GetWindowText(hWnd, szBuf, sizeof(szBuf)/sizeof(szBuf[0])))
{
}
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]
|
|
|
|
|
*((LPWORD)buf) = length; - this will copy sizeof(WORD) bytes into the first sizeof(WORD) bytes of your buffer
*(buf) = length - this will convert your integer (length) to a TCHAR and put that into the first TCHAR pointed at by buf.
So let's assume WORD is 2 bytes and TCHAR is also 2 bytes (unicode), in this case the 2 versions should produce the same result, but if you compile wihout unicode, TCHAR being 1 byte then in the second case, only 1 bytes will be changed in your buffer while the 2nd byte is left unchanged, you would probably get a warning from your compiler too ('conversion from int to char, possible loss of data' or similar).
On a sidenote, could you show me where you read this:
gabbana wrote: So now it says the FIRST WORD needs to have the length of the string in the edit field, which I retrieved before.
please?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Okay, now I think i found some information.
Lets start with Bits and Bytes:
A BIT can be 1 or 0. So we have 2 options
A BYTE contains 8 Bits. So we have 2^8 possible option (ASCII/ANSI) So we have all the 256 chars.
A WORD contains 16 Bits (2BYTE)
A WCHAR (wide char) contains also 16bits (2BYTE) -> chinese languag and so on need 2 Bytes for one char.
A Pointer (I said its normally a void point but that was wrong) is normally a pointer to a specific datatype, for example WCHAR *buf -> means we have a Pointer which points to ONE WCHAR somewhere in memory (as long as we allocate space)
So now we allocate space: *buf = new WCHAR[16]; This means we allocate 16 bits per char, so we have allocated 2*16 bytes = 32 bytes which means 2^32 bits.
So if we use the example with edit field, we get an integer (the length) and convert it to a WORD. BECAUSE the edit field must return something >0 we CAN convert it to an unsigned integer, a WORD right?
-> Now why do we need the following?
*((LPWORD)buf) = length
And why does
*(buf) = (WORD)length
also works ?
So we know that WCHAR contains 2Bytes. A WORD also contains 2Bytes.
So the point normaly shows to the firt wchar which is also a WORD in this example. So we can easily move the length to this location. Right ?
But why the first way ?
So it could be that if we does not using unicode, the pinte would only show to the first ONE byte in the memory. And then we need to convert it it first to an LPWORD to be sure the pointer shows to the FIRST 2Bytes, a WORD in memory. And so it works.
I hope its not too long and someone can confirm my explanation.
Thank you very much.
bye,
gabbana
|
|
|
|
|
Oh I see the first two answers now. Thank you very much but it would be great if you also confirm what I say in the last post. I think the unicode stuff I mentioned is right, juhuu.
|
|
|
|
|
As far as i can tell, you understood it quite well. Just to clear things up, a pointer alone always points at 1 byte in memory, giving it a type is, how to say, just a more clear, logical way of handling things. Hmm, hard to explain what i mean, i try to give an example:
WORD *WordPointer = (WORD *)malloc(sizeof(char));
So, althorough WordPointer is assumed to be pointing at a WORD being 2 bytes, it still points at the 1 allocated byte. So if then you do
*WordPointer = 3;
It will write 2 bytes in memory but we only allocated 1 byte, this can result in 2 (or maybe more) things:
-You get an access violation because you are trying to write a memory location (the second byte) that does not belong to your process. This is a better result because it is much easier to track down and correct.
-The second byte of the word actually belongs to your process but is part of something else, for example an integer's first byte you use somewhere else, then you owerwrite this changing your integer, this problem is much harder to track down and correct because it doesn't result in an error right away but maybe later when you try to use your integer and see that it has some bogous value and you have no idea where it came.
</smartass_mode>
I hope this is clear, don't want to lecture you, just thought this info might be useful for you.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Ahh okay great. Thank you very much.
I think I will try a bit and see what the debugger shows to become a better "feeling" of how something of that happens so that I know "Aahh, I have an error with the memory allocation".
|
|
|
|
|
I wanted to know what is difference between CreateThread & AfxBeginThread
while creating thread?
Thanks in advance
Nikesh
|
|
|
|
|
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_
|
|
|
|
|