|
t1 and t2 are stack variables. Your allocation makes the compiler to reserve memory on the stack for t1 and t2.
The order of the allocation is undefined (I think).
So if you are lucky, it the stack allocation starts with t2, followed by t1. You copy the content of t1 to t2, including the terminating \0, and nothing happens. Output will be "Codeproject". (If you output t1, it will be "eproject").
If it´s allocated the other way around, it will still output "Codeproject", but your program will likely go bananas when the function terminates, due to the corrupted stack. (The stack also contains the address to return to, usually the address to the function that called the present function).
There are a lot of articles about what´s on the stack, written by people with far more knowledge on the subject than myself. If you want accurate info, pls. read those articles.
|
|
|
|
|
Depends on what you do after the code provided ... all after the third character can be overwritten at any time so, this data, is unsecured.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
I have a tooltip defined for system tray icon. I am going to set the timeout for display using uTimeout member. But time out never happens. Any idea?
|
|
|
|
|
Does anyone know if there is an SQL server for development purposes for free? I don’t care if it is limited to a trivial number of entries. What I need to do is define some tables, put in some data (a trivial amount) and then beat on it with my code in C++. In the actual site there is a real SQL server which will do real work, but I need something on my local disk for testing purposes.
Thanks,
Ilan
|
|
|
|
|
Thanks,
I found it myself.
|
|
|
|
|
hi i have a promblem that i have a string "首YはYO二OK亜KM。M"
i want get the & of head but i can't getting the right~
like this:
CString m_str="首YはYO二OK亜KM。M";
wchar_t *m_T=(LPWSTR)_bstr_t(m_str);
wchar_t m_tem=*m_T;
fontOld=pDC->SelectObject(pFont);
pDC->TextOut(rc.left+m_Width,rc.top+m_Depth,&m_tem);
but it display 首???????? i only want 首
thank in advance very much.
nothing
|
|
|
|
|
why not you try char array ? so that u can take the particular item .. m_tem[1];
thanx
V
|
|
|
|
|
ebinaini wrote:
wchar_t m_tem=*m_T;
wchar_t m_tem=m_T[0];
.. maybe, so that your m_tem is really only one char wide.
BTW, there must be better ways (meaning safer ways) to do this :
ebinaini wrote:
wchar_t *m_T=(LPWSTR)_bstr_t(m_str);
~RaGE();
|
|
|
|
|
TextOut displays a string, not a character. Passing &m_tem , TextOut still treats it as a string and, as such, is exactly the same as m_T .
By the way, as has been alluded, CString doesn't like to be messed with internally like you might be trying. Use a char array instead, or you're going to blow something up later.
Bob Ciora
|
|
|
|
|
I have a dialog that use to send data using IP address. The dialog include a IP address box to key in the IP address which is the destination IP address. It also have a send button that when I click on it, it will send the data to the destination that I key in the IP address box. Beside that, the dialog also include some button that have their name such as open door, close door, on aircon etc. When I click on those button, it will automatic send the button name to the destination.
This dialog just add all those button but did not do the program inside the dialog. So the dialog cannot work exactly what I mention above. I don't know how to do the program for the send button and the IP address box which is when I key in the destination IP address and the message that I want to send and last click on the send button, it will send the message. thank you very much if somebody can help.
|
|
|
|
|
Hi,
I have a problem with using a path. I have to obtain the program files' path programatically, therefore I use this function.
CString PFPath;
SHGetSpecialFolderPath(NULL,PFPath.GetBuffer(_MAX_PATH),
CSIDL_PROGRAM_FILES, FALSE);
MessageBox(PFPath);
and the message box says:
C:\Program Files
I need to add something at the end of this string and then i try to use it in another function which needs the paths in double back slashes like:
"C:\\Program Files"
Then I try to do a conversion in PFPath in order to double the backslashes to change from
"C:\Program Files" to "C:\Program Files"
int i=0;
i = PFPath.Find("\\",i);
while( i>-1 )
{
CString found;
found.Format("Backslash found at index: %d",i);
MessageBox(found);
PFPath.Insert(i,(CString)"\\");
MessageBox(PFPath);
i += 2;
i = PFPath.Find("\\",i);
}
if(i==-1)
MessageBox("No more backslashes");
MessageBox(PFPath);
The message box output of this path is:
Backslash found at index: 2
\
No more backslashes
\
As seen, the insert function turned the whole string into a single backslash instead of inserting one.
CString WholePath = PFPath + (CString)"\\some_folder\\myfile.exe";
SHELLEXECUTEINFO shellInfo;
...
shellInfo.lpFile = WholePath;
::ShellExecuteEx(&shellInfo);
The conversion cannot be done properly, and shellInfo.lpFile needs double slashes. Therefore ShellExecuteEx cannot receive the path.
I have also tried the '\' conversion issue with CString::Replace ; CString::left, CString::Right and concetanation with operator + . Now I'm almost convinced that it is not possible to do it with the CString class.
Is there any other way to convert the '\' to '\\'?
Regards and thanks in advance,
Caykahve
-- modified at 5:49 Monday 29th August, 2005
|
|
|
|
|
Hi,
if you want to get the path of your application, just access your
theApp.m_pszHelpFilePath member. Its extension is "hlp". Just cahnge it to "exe".
Regards
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
It's not my application actually.. There might be several applications whose "theApp" I don't have.
|
|
|
|
|
Sorry,
I missed the point. If your want to wrap your path name, try something like that:
CString getWrapped(const CString& Text, char Esc)
{
CString buffer;
int size = Text.GetLength();
buffer += '"';
for(int i = 0; i < size; i++)
{
char c = Text[i];
if ((c == '"') || (c == Esc))
{
buffer += Esc;
}
buffer += c;
}
buffer += '"';
return buffer;
}
CString test = getWrapped(path, '\\');
Is this your question?
Regards
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
The example I posted recently was previously developed for the std::string class.
If you are just using CString objects wrapping is even easier:
CString test;
test += "\"";
test += path;
test += "\"";
test.Replace("\\", "\\\\");
Regards
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
I do not want to put quotation marks to both ends of the text.
I want to convert a string (i.e. CString) like C:\Program Files to C:\\Program Files - which is doubling the back slashes...
Regards
|
|
|
|
|
Ok, that's a one-liner
If you have
CString test("C:\\Program Files");
just call
test.Replace("\\", "\\\\");
Regards
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
When the string has a backslash it acts differently. I know that to add a quotation mark, you need a backslash in front of it. CString::Insert and CString::operator + act different when there is a backslash in the CString object. I'm sorry to say that I could not get a result with the code you sent either.
Regards
-- modified at 7:48 Monday 29th August, 2005
|
|
|
|
|
Ok, please give me a moment...
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
I'm a bit confused...
I can't find a difference between CString::Insert and CString::operator+
I sent you an email with the example I have coded...
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
I see that it works with your code, but not with the code I have, which is similar to yours (see my initial message). I don't understand.
Thanks and regards
|
|
|
|
|
Hi,
this time I implemented your posted code back-to-back and got the same error.
The problem is related to the CString::GetBuffer() method.
CString::GetBufferSetLength() should fix the problem.
But I would prefer:
char buffer[_MAX_PATH];
SHGetSpecialFolderPath(NULL, buffer, CSIDL_PROGRAM_FILES, FALSE);
CString PFPath(buffer);
Regards
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
Thank you very much, that works.
Regards
|
|
|
|
|
caykahve wrote:
and the message box says:
C:\Program Files
I need to add something at the end of this string and then i try to use it in another function which needs the paths in double back slashes like:
"C:\\Program Files"
Then I try to do a conversion in PFPath in order to double the backslashes to change from
"C:\Program Files" to "C:\Program Files"
You don't actually need any conversion. The double back slash is needed only when you are writing a string literal in your code. That's because the back slash is a escape character (used in combinations like \t, \r and \n, to represent a tab, carrier return, and line feed characters), when what you want is an actual back slash character, you need to type it twice. However, the double back slash pair represents one (single) back slash character in memory.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
I have a problem on updating an sql server database.
The connection string that I give is as follows:
"Description=description name;DRIVER=SQL Server;SERVER=server_name;APP=Microsoft\x00ae Visual Studio .NET;WSID=wsid;DATABASE=dbtest;Network=DBMSLPCN;Trusted_Connection=Yes"
I open multiple tables of the database as snapshot.
The first problem that I have is that I want to search for a value of a field in one of the tables, so I use the MoveFirst and MoveNext functions. The MoveNext function doesn't work!
The second is that when I run the AddNew function I get the error "Recordset is read-only"!
Does anyone know how can I get the privilege to move in and change the database?
Thanks in Advance
sirtimid
|
|
|
|