|
Hi, everyone!
I think memcpy is faster than strcpy and they really
do the same thing. So I think we should not use memcpy
instead of strcpy.
Am I correct?
Thanks in advance,
George
|
|
|
|
|
You can use memcpy when you want to copy a 'raw' piece of memory. There is no such thing as a concept of a C-string ( null-termination) or even objects in it.
When you want to work with strings it is best to use std::string (or CString if you like) and not to work with strcpy or the like at all.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
Thanks, jhwurmbach buddy!
I am always using strncpy in C++ program. How to use
std::string to do string copy? Do you mean this way,
Source code:
--------
string src = "abc";
string des = src.substr (0, 2);
--------
regards,
George
|
|
|
|
|
Yes, if the first two letters are what you want.
You can make a std::string from a LPCTSTR returned by the API simply by saying e.g.
LPCTSTR s = GetWindowText();
std::string t (s); the other way round is:
SetWindowText( s.c_str() );
YOu can read more about std::string (and CString) in the Codeproject C++ FAQ.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
Thanks, jhwurmbach buddy!
George
|
|
|
|
|
strcpy copies a given block of memory up to the point it finds a "0" or NULL in the memory block. strncpy will do the same thing up to a given number of charaters. memcpy will copy the given number of characters.
Assume you wanted to copy the following data:
ABCDE\0MNOPQ
Notice, that there is a NULL character in the 6th position.
strcpy (dst, src) would result in: ABCDE\0
strncpy (dst, src, 8) would result in: ABCDE\0
strncpy (dst, src, 3) would result in: ABC
memcpy (dst, src, 3) would result in: ABC
memcpy (dst, src, 8) would result in: ABCDE\0MN
If you want to copy raw data, use memcpy. If you want to copy C-strings (instead of std::strings) use strcpy or the safer strncpy.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks, Tim buddy!
George
|
|
|
|
|
Problem:
while downloading a huge file from a ftp server, if my service lost the connection in between, how can i resume the download?
The problems are
1: Since it is a huge file, it is not a good idea to restart the download.
2: If we are download by parts in different threads, then each thread should have different connection. This will not work when the server restricts the number of users.
Anybody please suggest a better algorithm for this.
|
|
|
|
|
that depends on whether the ftp server runs a version of ftp which allows resumes AND you have an ftp client which also supports Resume
cheers
bryce
---
Publitor, making Pubmed easy.
http://www.sohocode.com/publitor
|
|
|
|
|
To resume a download you need to use the REST command:
REST <byte offset="">
The REST command will make the server start at a give byte offsett and not at the start of the file.
When you send that command the server will reply with either a negative response, or the code 350, which means it will start at the byte offsett you've specified.
NOTE: The REST command must be followed by a service command (RETR or STOR).
-Rune SVendsen
|
|
|
|
|
When writing some text to a DC, it appears that the font creates it's own background for it's character spacing. I was wondering if there was a way to change this. Thanks.
bob
|
|
|
|
|
CDC::SetBkColor()<br />
CDC::SetBkMode()
~RaGE();
|
|
|
|
|
CDC::SetBkMode
int SetBkMode( int nBkMode );
Return Value
The previous background mode.
Parameters
nBkMode
Specifies the mode to be set. This parameter can be either of the following values:
OPAQUE Background is filled with the current background color before the text, hatched brush, or pen is drawn. This is the default background mode.
TRANSPARENT Background is not changed before drawing.
Remarks
Sets the background mode. The background mode defines whether the system removes existing background colors on the drawing surface before drawing text, hatched brushes, or any pen style that is not a solid line.
|
|
|
|
|
Iam doing a project in MFC using ODBC classes which can connect to any ODBC compilant database ..
1.I created a ODBC DSN for a access database mdb .WHile creating the DSN i did not specify any SYSTEM DATABASE .
2.When i executed the program ,it gave me an error "could not find "c:\cb\debug\dbo.db" .FIrst of all the access database i have given in DSN creation is different from that pointed out in the error message . Secondly the path shown in the ERROR message is the path of the executable .
How do i solve the problem .....
Every LIFE is unique and so there is no use in comparing ....
|
|
|
|
|
Iam doing a project in MFC using ODBC classes ..
1.I created a ODBC DSN for a access database mdb .WHile creating the DSN i did not specify any SYSTEM DATABASE .
2.When i executed the program ,it gave me an error "could not find "c:\cb\debug\dbo.db" .FIrst of all the access database i have given in DSN creation is different from that pointed out in the error message . Secondly the path shown in the ERROR message is the path of the executable .
How do i solve the problem .....
Every LIFE is unique and so there is no use in comparing ....
|
|
|
|
|
hi there,
Set the listctrl styles to OWNER_DATA and put a break point in OnItemChangingList function, it does not enter this function at all.
I can some how handle it in OnItemChangedList function by comparing the uOldState, but my question is why does not OnItemChangingList function not called when the list is in this style. If the control is not set to OWNER_DATA it works fine.
eagerly waiting for solution
bye
rajs
|
|
|
|
|
hi
well, I am trying to do the following:
I put a button on the dialog and associated it with exe file
that is:
void CMyView::CMyButton()
{
CIniReader ini;
ini.setINIFileName("./gm.ini");
CString ttl;
ttl = ini.getKeyValue("total", "path");
WinExec(ttl,SW_SHOWNORMAL);
// change the path in .ini file
//WinExec("D:\\Misc\\StarCraft\\StarCraft.exe", SW_SHOWNORMAL);
}
I have drawn the icon on the button (found the article for Button Image here). It works.
but, how to make the program so that when I change the .exe to execute in ini file, the icon on the button take the icon of exe
|
|
|
|
|
Dear Friends,
Hi !
I would like to retreive the program name of my program as a variable so can use in my program.
Is there is any such Function in WinAPI.
Kindly write to me.
Thanking you.
Adarsh
|
|
|
|
|
|
Hi PJ Arends
Thanks!
LPSTR also gives a name of a program with it`s complete path.
Anyway thanks a lot.
Bye
Binay
|
|
|
|
|
Hi PJ Arends
Thanks!
LPSTR also gives a name of a program with it`s complete path.
Anyway thanks a lot.
Bye
Adarsh
|
|
|
|
|
I tried to use CTreeCtrl::SetItemState, setting the flag TVIS_SELECTED. But I found that only one items was highlighted. How can I highlight a set of items? Thanks
|
|
|
|
|
TreeCtrl does not natively support multiple selection you will probably need to track selection state externally and use customdraw etc etc. Maybe block tvn_selectionchanging, listen to mouse leftclick and evaluate it in conjunction with keyboard state using HTREEITEM TreeView_HitTest(HWND hwndTV, LPTVHITTESTINFO lpht) or similar. Its not a simple ask.
You also need to define behaviour such as whether selecting a parent node auto selects all its children and whether the user can select nodes at varying different levels of the tree at the same time.
|
|
|
|
|
How could I highlight certain items in CTreeCtrl? I tried to use CTreeCtrl::SetItemState(),setting the flag as TVIS_SELECTED. But only one item was highlighted. Thanks.
|
|
|
|
|
AKAIK, it is only possible to select one item in the standard CTreeCtrl . Look in the CP articles for some enhanced CTreeCtrl .
~RaGE();
|
|
|
|