|
The safe way is to:
BSTR temp = 0;
HRESULT hr = get_Path(&temp);
m_bstrNewPath.Attach(temp);
The reason is that get_Path allocates the string and needs to return you a pointer, so the parameter uses double indirection of (chartype) ** .
_bstr_t, for various reasons, cannot safely wrap this operation.
There are a few circumstances where you can avoid the temporary (but you have to know exactly when - and when not). So rather play it safe and use above construct. There is no performance hit involved.
in get_Path, path is an [out] only parameter (i.e. the original valeu is ignored).
If you have a method with an [in/out] parameter, use:
_bstr_t path = ...;
BSTR temp = path.Detach();
HRESULT hr = comObject->ModifyPath(&temp);
path.Attach(temp);
if (FAILED(hr))
{
}
note the different order of attaching vs. error handling.
|
|
|
|
|
Hello everyone,
In the sample, I am wondering what is the life cycle of variable b_? Could we access variable b_ in catch block?
I have this confusion is because,
1. I think b_ is member variable, and we should be able to access it anywhere in the class itself, so we can access b_ in catch block;
2. I think b_ is declared and initialized in try {} block, and catch exceeds the {} of try, so we can not access b_ in catch block.
Which option is correct?
http://www.gotw.ca/gotw/066.htm
class C:
{
B b_;
C::C()
try
: b_( )
{
}
catch( ... )
{
}
};
thanks in advance,
George
|
|
|
|
|
George_George wrote: 2. I think b_ is declared and initialized...
I do see it as the member of the class. The variable is not being declared in the catch block.Had b_ been declared and initialized within the class it won't be available for use in the catch block. You can try doing this using a simple example:
class C
{
int b_;
public:
C():b_(10)
{
try
{
int t = 0;
int j = 20/t;
int c = t;
}
catch( ... )
{
cout<<b_<<endl;
}
}
};
Let me know that if I understood your problem statement correctly...
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Thanks _AnShUmAn_,
I have verified that we can access b_ in catch block. My question is answered.
regards,
George
|
|
|
|
|
Hi Experts,
1.Is there any simple artical to Darg Drop a file from ListView to ListBox?
2.I have created a file onto harddisk. Can I modify its data from in between?
|
|
|
|
|
Hmmm , I haven't tested this , but , have you enabled Drag and Drop on the HWND of the two controls? That way you will get a drop message when the user drags an item , then you should subclass the controls WndProc and handle only that message (call DefWindowProc when done handling) so that you can emulate Drag & Drop behaviour for the controls. You can do File Manipulation within the message handler itself.
The tears shed in vain
and the hatred and pain
will be nothing but dust
at the end of the day
|
|
|
|
|
Dear all,
can any body explain me what is the need of interface
are they just be usefull only for COM application...
Thanks in advance..
Vikas da
vikas da
|
|
|
|
|
tasumisra wrote: are they just be useful only for COM application...
Use of interfaces increases the modularity and maintainability of the code. Once COM components are developed the entire system is seen as a set of blocks that gel together to provide some functionality. Usually if you want to use third party softwares/functionality interfaces provide you the mechanism for achieving this.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hi All,
I want to display files huge files (Hexedit display format)in MFC. Any idea about doing this...
Manjunath S
GESL
Bangalore
|
|
|
|
|
If i have a triangle with following angles(in degree) and lines
A(57),B(62),C(61)
say line between A and B is c
line between B and C is a
line between C and A is b
Now suppose i divide angle B in two equal parts by drawing line on line b from angle B. i.e. i draw a line from point of angle B to line b
then i want to get the coordinates of point where new line touch line b
please suggest if there is any formula or algo to get it
Manoj Kumar Chauhan
|
|
|
|
|
use vector to determine the new line,
then get the cross point of the two lines.
|
|
|
|
|
How to use the vector?
please give any example or sample
Manoj Kumar Chauhan
|
|
|
|
|
It is a mathematical problem.
It can be found in google.
For example, A is at (x1,y1), then vector A,Va=x1+y1i, so Vb=x2+y2i
You can use AxB A.B, hope it helps.
|
|
|
|
|
hi
i have a application to disable the popupmenu start button when it is started at the same time stop buton should be enabled ,like same case for stop button also(disable when it is in on)
with advanced thanks
k.guru moorthy
k.guru moorthy
|
|
|
|
|
Could you please rephrase? I didn't get you...
|
|
|
|
|
i hav a application in system tray based i.e when click the minimise button icon will be moved to system tray .
i finished all (i.e minise to tray and popup menu )
now the problm is there r two button called start ,stop button
when i clicked start button , corresponding function is doing well and the button should be disabled (stop button - enabled)
when i clicked stop button corresponding function is doing well and this button should be disabled (start button - enabled )
u say how to disable.
i tried using getting id of the button but run time error ocurs (NO SYMBOLS ARE LOADED FOR ANY CALL STACK FRAME )
please help me
k.guru moorthy
|
|
|
|
|
If you are using MFC, then you can do it as follows
GetDlgItem(IDC_BUTTON1)->EnableWindow( FALSE );
OR
m_btnButton1.EnableWindow( FALSE );
But why it crashes? How did you disable it?
|
|
|
|
|
Cbutton* newbutt=((CButton *)getdlgitem(id_popupmenu_start);
newbutt->enablewindow(true);
k.guru moorthy
|
|
|
|
|
Where are you calling this? And did you verify that the pointer is valid?
|
|
|
|
|
Did you want to disable button?
|
|
|
|
|
My program would crash when it goes to CListCtl::InsertItem().The codes like bellow:
//get_wstring() will return a std::wstring object here,count is the rows I want to insert
for(int i=0;i<count;++i){>
std::wstring str = get_wstring();
CString temp(str);
//m_list is a CListCtl control
AfxMessageBox(temp);
m_list.InsertItem(i,temp);//crash here
}
the codes would crash when str string is not in my local language page(so the content of temp would be a strang string).But AfxMessageBox works well.
Someone would like to tell me why and how to fix such errors?
Thanks.
Merry Chrismas!
|
|
|
|
|
The cause might be the std::wstring, or the construction of CString from std::wstring. Please try this and see if it also crashes?!
m_list.InsertItem(i, "test");
Maxwell Chen
|
|
|
|
|
Of course not.
No matter what content of temp(CString object),AfxMessageBox() would show the real content of temp.But when its content like "ß??z???"(string like this were read from some file),InsertItem() would crash.
modified on Tuesday, December 25, 2007 11:57:34 PM
|
|
|
|
|
kcynic wrote: the codes would crash when str string is not in my local language page
Make your application UNICODE compatible and then try.( by defining _UNICODE in the project settings )
|
|
|
|
|
Yes,I compiled the project as UNICODE version,I forgot to say.
|
|
|
|