|
and you expect us to do your homework ?
bad pupil
|
|
|
|
|
|
Done.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It enters to stack you must wait for it(FIFO).
|
|
|
|
|
|
Hamid. wrote: but next time ask for specific question and also use of a simple search
yes, but next time, don't give help to lazy people like that guy who didn't even make the effort of searching the web and the codeproject by itself
|
|
|
|
|
I'm agree with you if I could search so he/she could search himself/herself but I guess maybe he/she needs to this help.;)
|
|
|
|
|
Hi,
When using a buffer to intermediary help to make use of some functions…
If I want to have in the buffer the content of an Array, then I make:
pBuffer = &Array[0];
file->Write (pBuffer , sizeof (Array));
And there is no problem because the array allocates contiguous memory to hold the members and the pointer says where the Array starts, and with the “size of (Array)” I say how many elements have to be written.
But doing the opposite…
::RegQueryValueEx (hWkKey, "SubKey", 0, &dwType, pBuffer, &lnLength);
if (dwType == REG_SZ)
szValue = pBuffer;
else if (dwType == REG_BINARY)
for (int i = 0; i < lnLength; i++)
Array[i] = *(pBuffer + i);
delete [] pBuffer;
pBuffer = NULL;
The usual assignation works with the string because internally is like a char* and then both uses the start direction to allocate the data in their place till a '\0' is founded, but it should be made using a for when writing the data into the array because there is no way to say how long the array is (like '\0' by the char*) (isn't it?)
Array = *pBuffer;
;
&Array = pBuffer;
Array = pBuffer;
&Array[0] = pBuffer;
;
The meaning of the errors (but C2109) and the reason to have them is clear, but...
Is there any other possibility to do it, or the “for” must be used?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
I am not sure what your question is but have a look at memcpy(...)
|
|
|
|
|
I have taken look to the documentation and it seems to be what I asked for. But...
Quote:
"The memcpy function copies count bytes of src to dest. If the source and destination overlap, this function does not ensure that the original source bytes in the overlapping region are copied before being overwritten. Use memmove to handle overlapping regions."
but in the example both makes exactly the same,
Function: memmove with overlap
Source: quick brown fox jumps over the lazy dog
Destination: brown fox jumps over the lazy dog
Result: The quick quick brown fox jumps over the lazy dog
Length: 49 characters
Function: memcpy with overlap
Source: quick brown dog jumps over the lazy fox
Destination: brown dog jumps over the lazy fox
Result: The quick quick brown dog jumps over the lazy fox
Length: 49 characters
then... why is it said?
Can you tell me an example where the quote of MSDN is true?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Nelek wrote: then... why is it said?
what is "what" said? The part about overlapping source and destination? ????
|
|
|
|
|
Yes, what I write in quote.
It is supposed to give problems while overlapping, but the code that they put in the example (I paste some parts)
char string1[60] = "The quick brown dog jumps over the lazy fox";
char string2[60] = "The quick brown fox jumps over the lazy dog";
printf( "Function:\tmemmove with overlap\n" );
printf( "Source:\t\t%s\n", string2 + 4 );
printf( "Destination:\t%s\n", string2 + 10 );
memmove( string2 + 10, string2 + 4, 40 );
printf( "Result:\t\t%s\n", string2 );
printf( "Length:\t\t%d characters\n\n", strlen( string2 ) );
printf( "Function:\tmemcpy with overlap\n" );
printf( "Source:\t\t%s\n", string1 + 4 );
printf( "Destination:\t%s\n", string1 + 10 );
memcpy( string1 + 10, string1 + 4, 40 );
printf( "Result:\t\t%s\n", string1 );
printf( "Length:\t\t%d characters\n\n", strlen( string1 ) );
gives the results that I worte in the message above, and both are making exactly the same and working good. So I don't understand where the problem is. If I could see an example where the quote is true, then I would understand it better.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Nelek wrote: If I could see an example where the quote is true, then I would understand it better.
If the source and destination overlap, this function does not ensure that the original source bytes in the overlapping region are copied before being overwritten.
memmov "does" ensure that the original source bytes are copied before being overwritten.
There is no certain way to give an example where it memcpy fails because the results are not guaranteed. You would have to try experimenting to find a condition where it might fail repeatedly.
Also your documentation appears dated check this out[^]
|
|
|
|
|
Yes,
the only problem is that I am usually using VC++ 6.0 and it would be not the first time I check the MSDN page to look for something, try to use it, and lots of errors because it is for newer versions.
Because of that I use my program's help and my quotes sometimes are old.
But thank you for your time and explications. You have helped me to understand it better
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Don't quite understand the question, but there seems to be confusion about Arrays, Strings and CStrings. An Array is a continguous section of memory of which the compiler is aware of how it is organised.(Element Size, and Number of Elements). It is closely related to the Pointer to an Element Concept. However, whereas you can change a pointer point to a different location in memory, you cannot do this with a variable declared as an array name.[Error C2240] (The Compiler would soon loose track if you could do these things). A Pointer is more versatile than an array in this respect. However, the compiler still keeps track of the type(and hence size) of the object it points to. A pointer to void should be interpreted as a pointer to 'Nothing in Particular' It has only an address value, all other interresting titbits are ommitted. That means that the compiler cannot dereference a void pointer, it has insufficient information to do so. We use a Pointer to void as a generic pointer, which can be passed on by value, but which we must render usable as pointer by adding information, (i.e. Casting)
A String of characters is closely related to an array of characters, there is actually only one difference, when initialised with a literal text constant, the compiler adds automatically a terminating zero to a string. It would for instance not do that if you initialise an array of integers.
This brings us to a CString. Now, this is an entirely different kettle of fish. The items discussed above are essentially C-constructs, which can ofcourse be used in CPP. A CString is firmly a CPP Class, it is definitely NOT the same as a character array. The properties of a CString are not determined by the Compiler (as in Strings and Arrays) but are implemented as part of the Microsoft Standard Libraries. What makes it confusing for a novice is that aparently CStrings and Strings can often be used interchangably, and that the CString can be initialised to the value of a String. This is all due (and purposely designed to work this way) to the gymnastics carried out in the various methods of the CString class. As an example, A CString contains indeed a buffer containing the Null terminated string representing the value. The Cast Operator (LPCSTR) is written in such a way that it returns a pointer to this buffer. I Suggest that you experiment with the CString Class to get a feel for what I am about here. As for your own Array's, why not write your own dedicated class which keeps track of buffers and sizes, and which 'act' like arrays by using the various 'operator' overrides
LateNightsInNewry
|
|
|
|
|
Thanks for such a good explanation.
So szValue = pBuffer works fine because the adress of pBuffer is actually being asigned to that intern buffer of the CString, and the rest of the information is find out internally (i.e. the length of the string is determined with the "\0"), but...
&Array[0] = pBuffer can not be made because, although the type of data is the same and both will point to the same place, the Array has a fixed length due to the allocation or the creation with [M], and the pointer can not really determine how many place is needed...
But pBuffer = &Array [0] works fine because when the pBuffer is used in other place, the most of the functions that use a buffer need a parameter "sizeof (...)" to determine the needed length of the data field. I.e. the &nLength by using RegQueryEx (..), or file->Write ( pBuffer, (n * sizeof (BYTE)) )
or sizeof (Object);
Is that correct?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Hi,
How can i set the video position using MCI to a specific time using the format hh:mm:ss ?
Regards,
sdancer75
|
|
|
|
|
|
hi,
i dont use the mci_window. I can use the Seek(frame_number) to position my video but it does not work when i want to use time format. Any suggestions?
Regards,
sdancer75
|
|
|
|
|
I wrote code for set postion of window for mci I think two or three years ago but I forgot it I will be see my projects and give you an answer.
|
|
|
|
|
Hey thanks,
I think I found a solution. All I had to do is to multiply the hour with 3600 ( sec) * 1000 to convert it to milliseconds the minutes with 60 * 1000 and seconds with 1000.
Finally I add the hour+minutes+secords and the final value is the position to mseconds.
mseconds = (hour * 3600 * 1000) + (minutes * 60 * 1000) + (seconds * 1000)
It worked.
Thank you.
sdancer75
|
|
|
|
|
I gald that your problem solved.
|
|
|
|
|
I have an ActiveX control which is similar to a button, I write the caption on to the control with the following:
pdc->SetTextAlign(TA_CENTER | VTA_CENTER);
pdc->SetBkMode(TRANSPARENT);
pdc->ExtTextOutW(buttonCntr.x, buttonCntr.y, ETO_CLIPPED, rcBounds, InternalGetText(), NULL);
Which all works OK, until the caption of the control is long, can I get the text to wrap on to multiple lines by some means, as is the case with CButton?
Thanks
Kalvin
|
|
|
|
|
try DrawText/DrawTextEx instead of ExtTextOut
-c
|
|
|
|
|
Thanks, that's done the job, partly! I am now using:
pdc->DrawTextEx(InternalGetText(), (LPRECT)myRect, DT_CENTER | DT_WORDBREAK, NULL );
Which does multiline and centres the text horizontaly in the rect., but I can't get it to centre vertically.
DT_VCENTER would appear to do this but it is only effective when combined with DT_SINGLELINE, and single line is def. not what I want. Any further ideas?
Kalvin
|
|
|
|
|