|
Manish_mnp wrote: CString str;
str = "Manish";
TCHAR *tch = new TCHAR[10];
tch = str.GetBuffer();
It is not a good idea to get a pointer to the CString internal buffer (have a look a t documentation). You'll better copy the buffer content to the TCHAR array.
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.
|
|
|
|
|
Your code will 'work' but is plainly wrong:
TCHAR *tch = new TCHAR[10];<br />
tch = str.GetBuffer();
You create a new buffer of 10 characters and then you make it point to another array, so you will loose ownership of your pointer resulting in a memory leak. Moreover, you point to something that is used internally by the CString class which can reallocate it and then you'll be in BIG troubles. And, you MUST call ReleaseBuffer once you called GetBuffer. You should really look at the documentation of that function before using it that way
ch = new char[10];<br />
<br />
ch = "Manish";
Once again, you allocate an array of 10 characters then you make the pointer point to another location resulting in a memory leak.
Here[^] is a nice link about those conversions
|
|
|
|
|
Manish_mnp wrote: Now tch will contain Manish.
No, it just points to str 's internal buffer. It also introduces a memory leak as tch no longer points to the address returned by the new operator.
Manish_mnp wrote: ch = "Manish";
You've made the same mistake...again. The pointer ch no longer points to the address returned by the new operator, but to a string literal instead.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
for casting from CString to TCHAR, you have the (LPCTSTR) cast operator in the CString class :
TCHAR pStr[50] = {0};
CString str = _T("Hello World");
::tcscpy(pStr, (LPCTSTR)str);
for casting from a TCHAR string to CString, you can simply use the CString constructor :
TCHAR pStr[50] = _T("Hello World");
CString str1 = pStr;
CString str2 = CString(pStr);
never use GetBuffer() method if you don't modify the CString's internal buffer. moreover, when you use GetBuffer() you have to release the buffer with a subsequent call to ReleaseBuffer() .
-- modified at 9:12 Tuesday 6th November, 2007
|
|
|
|
|
toxcct wrote: TCHAR pStr[50] = {0};
CString str = _T("Hello World");
pStr = (LPCTSTR)str;
You might want to rethink this.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: You might want to rethink this
:->
is it better now ?
|
|
|
|
|
i have a listView control has over 1000 no of items displayed, and a text box on which user types to filter the items in listview.
my problem is how to filter the items in ListView contorl. is it possible to hide contents in ListView? or any other idea to do so ?
Thanks & Regards
|
|
|
|
|
nitin3 wrote: is it possible to hide contents in ListView?
No, you have to change the ListView content.
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.
|
|
|
|
|
I would make it, saving the original data in a place, and then according on the filter, take the relevant data, erasing all datas in the list ctrl and filling it another time.
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
|
|
|
|
|
You could make two controls, and one will always be visible and enabled and the other one will always be hidden and disabled. That way the main (unfiltered) control does not need to be recreated each time, which makes things easier for you, Windows and the user.
I need to do the same type of thing that you are describing and that is how I intend to do it.
There are many other possibilities, depending on what you need or want to do for the user.
|
|
|
|
|
Hi all,
I have made a dialog based application. In that application from the main dialog box i am opening a second dialog box, on that dialog box i have made a button control and on clicking the button a context menu appears. Now my problem is i have to write functions on items of that context menu. i derive them from the class on which button is made that is second dialog box class.
Function is being made in the second dialog box class but when i write code for displaying the message box....Nothing happens on the click event.
Can anybody please solve my problem.
Thanks in advance
|
|
|
|
|
can anybody tell me how to print the datagrid.I am using ado to load the datagrid
||SnAkeBed||
|
|
|
|
|
iam not sure about any api which prints the data grid. but i can suggest you some technique to achieve your task. even i use the same technique, to get my data printed.
1.write a function to print the data in the grid to a text file.
2.using system command or createprocess command, try to print it.
if you want, then i can share the function iam using to print the flex grid contents. may be you may have to fine tune it to suit your data grid.
good luck.
|
|
|
|
|
I want to use ffmpeg library to convert my data(could be anythng simply camera picture or char *) to flv for live streaming. So i would like to know how could i include ffmpeg library into my application.
Regards,
Hemang
Hemang Raval
|
|
|
|
|
Hi,,
Is it Possible to include DLL project into the MFC Activex project's solution??
Thanks.
Ashish Bhatt
|
|
|
|
|
I need to get handle to EXE's icon to use it in other DLL/EXE.
How do we get it?
|
|
|
|
|
Hi,
I asked a few days ago about associating files with application and someone answered me with a link about icons, maybe that link is helpfull for u. This is my message[^]
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
|
|
|
|
|
Do you need to SHGetFileInfo ?
|
|
|
|
|
hi all,
in the dialog we are initializing through initdialog , as like in the form how we do that?
thanks
panthal
|
|
|
|
|
look for OnInitialUpdate
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
|
|
|
|
|
thank u nelek, just now i found that.
thanks for ur response
panthal
|
|
|
|
|
Hi,
I need to use a function that uses an array of pointers to a base class, and inside the function handles the pointer according to it's real type (Tha actual type is a derived class).
But i get an error when i call the function :
"Object0124.cpp(1905) : error C2664: 'InsertOutputData' : cannot convert parameter 1 from 'class Array<class Object0124::CDerived *,class Object0124::CDerived *> *' to 'class Array<class Object0124::CBase *,class Object0124::CBase *> &'
A reference that is not to 'const' cannot be bound to a non-lvalue"
I hope that it's clear:
h. file
----------
class CBase
{
int x;
CBase(){x=0;}
};
class CDrived :public base
{
int y;
CString z;
CDrived(){y = 0;z = _T("");}
};
typedef Array<CBase*,CBase *> m_CBaseArray;
typedef Array<CDerived*,CDerived *> m_CderivedArray;
void InsertOutputData(CBaseArray &arrInput,int Mode);
cpp file
---------
void Func()
{
CderivedArray arr;
CDrived var;
var.x = 10;
var.y = 16.533;
var.z = "value"
arr.Add(var)
InsertOutputData(&arr);//or InsertOutputData(arr);//error C2664
}
void InsertOutputData(CBaseArray & arrInput,int mode)
{
for(i = 0;j = 1; j < arrInput.GetSize(),!; j++)
{
if((arrInput.GetAt(i)->x != arrInput.GetAt(j)->x))
{
if(arrInput.GetAt(i)->y == arrInput.GetAt(j)->y)
{
//do something
}
}
}
}
Can anyone tell me what am i doing wrong???
-- modified at 5:22 Tuesday 6th November, 2007
|
|
|
|
|
Your code is unreadable. Check point 5 here[^]
|
|
|
|
|
mrobeda wrote: Can anyone tell me what am i doing wrong???
You treat
typedef Array<CBase*,CBase *> m_CBaseArray;
typedef Array<CDerived*,CDerived *> m_CderivedArray; as being related types.
They are not. The fact that CDerived is related to CBase does not make the container types releated.
What is related, though, are the dereferenced items of both containers.
What is Array<T>, btw?
A bastardized STL-class?
MFcs CArray, the handicapped step-brother of a STL-class?
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Array - inherit from MFC's CArray and created my AArray.
So how can i use a generic array that can handle different type of objects?
I need that the fuction will get each time a different type of object in the array.
|
|
|
|