|
prasad_som wrote: How it is different?
One is changeable, one is not. It's a bad design to frivolously provide access to CString 's character buffer via GetBuffer() unless it is absolutely necessary. The LPCSTR cast will suffice in most cases.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: One is changeable, one is not.
Agree. I was puzzled by " is not convert" thing. Anyway, it is one of solutions.
|
|
|
|
|
Usually you don't need that, because there is the operator LPCTSTR ( ) const; . However there is the method GetBuffer but use it with care...
hope it helps
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.
|
|
|
|
|
In my (non-unicode) programs I do like this:
char * cp = (char *) (LPCTSTR) CString;
It's not completely safe, since cp is a non-const char *, and LPCTSTR is a const pointer.
But as long as the resulting pointer (cp in this case) is used for reading only, it's perfectly safe.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
as you said, it's not "completely safe" (actually, not safe at all... lol).
first of all, you use C-Style cast, which is deprecated for using static_cast<>()
moreover, by using (char*) after that, you remove the constness of the string return, which is very very bad ! if you have to modify a CString string, use GetBuffer(), or copy its content into your own modifiable char array.
at last, if you have to deal with the Unicode/Ansi conversion, you should use T2A()-like (in your case) macros...
|
|
|
|
|
Did you even read what I wrote?
toxcct wrote: as you said, it's not "completely safe" (actually, not safe at all... lol).
Using a const pointer as a const pointer IS perfectly safe, IMO. Any objections?
toxcct wrote: you remove the constness of the string return, which is very very bad
What I wrote:
It's not completely safe, since cp is a non-const char *, and LPCTSTR is a const pointer.
But as long as the resulting pointer (cp in this case) is used for reading only, it's perfectly safe.
toxcct wrote: if you have to modify a CString string, use GetBuffer(), or copy its content into your own modifiable char array.
Other answers covered this case. There was no need to say it again.
toxcct wrote: at last, if you have to deal with the Unicode/Ansi conversion, you should use T2A()-like (in your case) macros...
What I wrote:
In my (non-unicode) programs I do like this:
One thing though, static_cast is nice, but then again:
What I wrote:
In my (non-unicode) programs I do like this:
And I do what I want in my programs, as long as they works as expected. Which they usually does...
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Yeah, but when you have to deal with bad written functions requiring char * instead of const char * but in fact never accessing the buffer for writing, you have to do it (of course you may also rewrite the bad written functions...)!
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.
|
|
|
|
|
That goes for quite a few functions in the RTL too...
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
See Mike's FAQ[^]
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverb
|
|
|
|
|
|
Hi, I am making one application using win32 and VC++.NET. I have one ‘list control’ and one ‘edit control’ in my dialog box. Now I select one item in list control and then I tried to click in edit box to write something in it, I lost selection from list control. Can I know what kind of style I have to use in my list control so it will not lost selection.
Thanks in advance.
Priyank.
|
|
|
|
|
Use LVS_SHOWSELALWAYS style while creating list control.
Or go to control poperties -->Appearance-->Always Show selection , and set it to true .
|
|
|
|
|
Thanks
|
|
|
|
|
Hello,
I have a dll which get injected into every running process.
I want all of my dll instances to share a certain char * variable.
However, even if I use the #pragma data_seg(...) definition, the variable holds the correct value only for one instance of it, which is the instance created to work with my app.
What can I do to share the variable?
Thanks in advance,
Shy.
|
|
|
|
|
Hi
Do you supply the value to the variable at the time of initialization in the shared data segment. Because your dll must be loading first of all in your process, and then in others, therefore, the shared pointer contains value correct only for your app's process.
Generally, pointer variables should not be shared among different mappings of a dll. The pointer variable will contain address pertaining to the address space of a particular process, and which will be invalid for other processes.
Pankaj
|
|
|
|
|
pnkj wrote: Do you supply the value to the variable at the time of initialization in the shared data segment?
This is my #pragma snippet:
#pragma data_seg("SHARED")<br />
char *myString = new char[100];<br />
#pragma data_seg()<br />
#pragma comment(linker, "/section:SHARED,RWS")
I also tried the following:
char myString[100];
pnkj wrote: Generally, pointer variables should not be shared among different mappings of a dll.
How would I use a string then?
Added:
I forgot to mention that I get a link error which appears only once, and if I compile again it disappears:
--------------------Configuration: HookingCore - Win32 Debug--------------------
Compiling...
HookingCore.cpp
Linking...
Creating library Debug/HookingCore.lib and object Debug/HookingCore.exp
LINK : warning LNK4039: section "SHARED" specified with /SECTION option does not exist
HookingCore.dll - 0 error(s), 1 warning(s)
|
|
|
|
|
The pointer itself may be shared among processes, but the data it points to is not. Use shared memory for that, check out CreateFileMapping() and MapViewOfFile()
|
|
|
|
|
Because this error \"SQL:Statement too long"\ i must write an SQL statement for 3 columns , because when i say CRecordset pSet;
pSet.Update(); The cause of this error ! (Update) because he is try to update all columns in my table , i have 400.000 records !
all i want is to Edit a field pSet.Edit();
My SQL statement is too long , but i dont write an SQL statement how can i short him ? or how can i write an SQL statement to retrieve just 3 columns from my table , please help me !?!?
Bravoone
|
|
|
|
|
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverb
|
|
|
|
|
I think you must read a sql book else you can not write a good program
|
|
|
|
|
You've failed to provide sufficient enough information for a meaningful answer. Have you derived class from CRecordset ? What does it look like? What does the code look like that opens the database and/or record set? What does the code look like that calls Edit() and Update() methods? The more relevant code that you omit from your post, the less help you're apt to receive.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
void CNoteDlg::OnSalveazaCr()
{
CWaitCursor wait; // Display a wait cursor
for(int i=0; i<m_list.getitemcount();i++)
{
="" if(m_list.getcheck(i))
="" {
="" cstring="" stemp,stemp1,stemp2,stip1,stip2,stest1,sanul1,
="" sluna,sluna1,sziua1,sdata;
="" cmainspace="" *pmainspace="new" cmainspace;
="" pmainspace-="">m_sTextDatabase.Empty();
pMainSpace->m_sTextDatabase1.Empty();
pMainSpace->m_sTextDatabase2.Empty();
pMainSpace->m_sTextDatabase3.Empty();
m_cod.GetWindowText(pMainSpace->m_sTextDatabase);
pMainSpace->m_sTextDatabase.TrimLeft();
pMainSpace->m_sTextDatabase.TrimRight();
m_nrNota.GetWindowText(pMainSpace->m_sTextDatabase1);
pMainSpace->m_sTextDatabase.TrimLeft();
pMainSpace->m_sTextDatabase.TrimRight();
m_datanota.GetWindowText(sLuna1);
m_datanota3.GetWindowText(sZiua1);
m_datanota1.GetWindowText(sAnul1);
pMainSpace->m_sTextDatabase3 = m_list.GetItemText(i,22);
pMainSpace->m_sTextDatabase2 = sLuna1 + "/" + sZiua1 + "/" + sAnul1;
CDatabase_Note pBun;
pBun.m_strFilter="note1="+ pMainSpace->m_sTextDatabase;
pBun.m_strFilter="note2="+ pMainSpace->m_sTextDatabase1;
pBun.m_strFilter="note3="+ pMainSpace->m_sTextDatabase3;
pBun.Open();
pBun.Edit();
while (!pBun.IsEOF())
{
int nIndexA = pBun.m_note1.Find(pMainSpace->m_sTextDatabase);
int nIndexB = pBun.m_note2.Find(pMainSpace->m_sTextDatabase1);
if ((nIndexA != -1) & (nIndexB != -1))
{
pBun.Edit();
pMainSpace->m_sTextDatabase3 = m_list.GetItemText(i,22);
pBun.m_note2 = pMainSpace->m_sTextDatabase3;
pBun.Update();
pBun.Close();
delete pMainSpace;
break;
}
//while
}
m_list.DeleteItem(i);
i--;
}
}
}
this is my code ... but somethig is wrong because it say SQL: Statement too long ! what can i do !
please help me !
i will wait your answer !
because i dont have one !
Bravoone
|
|
|
|
|
Bravoone_2006 wrote: for(int i=0; i<m_list.GetItemCount();i++)
...
i--;
Notice anything wrong with this?
Bravoone_2006 wrote: CMainSpace *pMainSpace = new CMainSpace;
It is not necessary to make this a pointer. Remove the new and delete calls.
Bravoone_2006 wrote: pMainSpace->m_sTextDatabase.Empty();
pMainSpace->m_sTextDatabase1.Empty();
pMainSpace->m_sTextDatabase2.Empty();
pMainSpace->m_sTextDatabase3.Empty();
The calls to Empty() are not necessary.
Bravoone_2006 wrote: while (!pBun.IsEOF())
I do not see anything in the while loop that is advancing the pBun object to the next record. Have you ensured that the while loop terminates.
Aside from the logic errors, what exactly are you trying to accomplish here?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
All i want is to Edit some fields !
How? i have done what you say but no change !
... how can i terminate the while loop , and where i must do in while pBun.MoveNext();?
Bravoone
|
|
|
|
|
Bravoone_2006 wrote: How? i have done what you say but no change !
None of my suggestions had anything to do with "editing fields." I would suggest posting your modified code snippet (please use the <pre> tags for this), and the results it is producing.
Bravoone_2006 wrote: how can i terminate the while loop ,
What is the while loop supposed to be doing?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|