|
hey, you want an exception safe copy ?
backup your object, then assign it the new object, and if it fails, restore its backup !
|
|
|
|
|
Thanks toxcct,
I agree with the general rule. But how to avoid the recursive invocation of assignment operator in your comments? Could you provide some code please?
regards,
George
|
|
|
|
|
toxcct wrote: hey, you want an exception safe copy ?
backup your object,
or take a picture of it.
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.
[my articles]
|
|
|
|
|
Hi toxcct,
I think in such pattern, swap should be implemented to a list of assignments of POD types, right?
BTW: if I am wrong, please help to correct code in your senses.
regards,
George
|
|
|
|
|
Thanks toxcct,
I agree that there is some issue in my code. It is appreciated if you could provide some pseudo code to correct my code to implement the using swap technique to implement a exception safe assignment operator.
regards,
George
|
|
|
|
|
Hi CPallini,
The code will cause recursive to invoke assignment operator?
regards,
George
|
|
|
|
|
Hi toxcct,
Two more comments.
1.
We are talking about the state of current object instance (this object), why you are talking about the state of parameter?
toxcct wrote: Yes. but I believe that the state of the parameter only may throw an exception, if its state is corrupted.
2.
I do not 100% agree. Since swap will create another new temporary object used to do swap. The creation of new temporary object may cause bad_alloc exception.
toxcct wrote: so if a is OK, then swapping it with this would be OK too...
regards,
George
|
|
|
|
|
George_George wrote: We are talking about the state of current object instance (this object), why you are talking about the state of parameter?
1) because : if the state of the parameter is corrupted, the state of the current object could have been corrupted too. but as long as we're assigning a temporary object first, the current object's assignment is exception-safe !
2) not sure for this one. isn't bad_alloc sent only when allocating memory on the heap (using new) ? here, temp is on the stack though !
|
|
|
|
|
Thanks toxcct,
In which step do you think the state of the input parameter will be corrupted? Could you provide some pseudo code please?
toxcct wrote: 1) because : if the state of the parameter is corrupted, the state of the current object could have been corrupted too. but as long as we're assigning a temporary object first, the current object's assignment is exception-safe !
regards,
George
|
|
|
|
|
Hi,
when I pass a String from VB to C++dll, the code will work, the string will appear on a MessageBox called from the Dll.
When i click Ok the following error message appears: "Wrong Dll_Calling Convention" !!!????
The Code
VB:
<br />
Private Declare Function fnWin32DLL02 Lib "E:\WORKING\OMRON\GDT\EigeneDLL\C++ DLL mit VB (Test01)\Win32DLL02.dll" (ByVal a As String) As String<br />
<br />
Private Sub Form_Load()<br />
<br />
Dim s As String<br />
<br />
s = "Übergabe aus VB"<br />
fnWin32DLL02 (s)<br />
<br />
End Sub<br />
Cpp:
<br />
WIN32DLL02_API BSTR fnWin32DLL02(LPCSTR s)<br />
{<br />
MessageBox(NULL,s,"Info",MB_OK); <br />
return CComBSTR (BSTR("abc"));<br />
}<br />
When i change the LPCSTR s to BSTR s, ...the same error appears !
Could you imagine where the error comes fom ?
Many Thanx and best regards
Croc
|
|
|
|
|
Hey Croc, have you seen my (now old) reply?
http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=2381364[^]
You have to use __stdcall calling convention.
Furthermore you need:
(1) to use SysAllocStringByteLen("hhh", 3) to allocate the returned string
(2) use LPCSTR (as you done in the posted code) for the input string.
Good luck!
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.
[my articles]
|
|
|
|
|
1000 *TH*A*N*X* PALLINI,
now it work's an no sry i was to fast, so i didn't remember the __stdcall !!!!!!!!!!!
Thanx again & best regards
Croc
|
|
|
|
|
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.
[my articles]
|
|
|
|
|
This is exactly what CPallini and I were talking about when you posted about this before. The C++ side needs to have __stdcall calling convention. This makes the order parameters are put on and pulled off the stack (and which side is responsible for cleanup) compatible with VB. Otherwise your stack is trashed on the return from the call, hence the error your're seeing. You're fortunate, in the past the error would have been silent and your C++ would have blown up spectacularly the next time it made a function call .
You need to find the definition of WIN32DLL02_API and make sure it includes __declspec(__stdcall)
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Hi Matthew,
i added
#define WIN32DLL02_API __declspec(_stdcall) in the definition of WIN32DLL02_API, but without this the code worked too !???
Best regards
Croc
|
|
|
|
|
Hi friends,
I want to send my dialog box to the system-tray when "WINDOWS key + D" is pressed(Show Desktop),
but I don't know which message is sent.
I have captured all messages that has sent to my dialog by SPY++, but none of the is acceptable.
Since my dialog has no border (it has no caption) and subsequently it has no minimized property in the dialog properties, I don't know how to handle the message.
By the way, I handled "OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)" message, but the message is sent for Activating and Inactivating.
But I want to handle a message which is sent when "Windows key+ D" is pressed merely.
Thanks.
|
|
|
|
|
you don't have to capture the message.
you just have to design your application so that it is minimized to the System tray.
same would happen then if you manually minimize it (with the upper right buttons), if you press the task bar button to reduce it, if you press Win+D (show Desktop), or Win+M (minimize all)...
|
|
|
|
|
Would you mind explaining me how can I design my application to send the dialo to the System tray automatically by minimizing the Windows (Win+D Or Win+M)?
|
|
|
|
|
Stop being rude. He is not being paid to help you out.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
...formerly known as brahmma
Codeproject.com: Visual C++ MVP
|
|
|
|
|
You considered Mohammad's question to be rude? As I see it, he was just asking for clarification.
"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
|
|
|
|
|
I thought he could have asked "Would you please", instead of "Would you mind".
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
...formerly known as brahmma
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Yes, he "could" have, but why, when they are both valid forms of asking the same question? Consider:
Would you please help me find the store?
Would you mind helping me find the store?
"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
|
|
|
|
|
I really don't know, but I felt that "please" would have been a more polite form. My apologies, if I am wrong.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
...formerly known as brahmma
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Please Lord for me please.
|
|
|
|
|
Would you mind explaining it to me?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
...formerly known as brahmma
Codeproject.com: Visual C++ MVP
|
|
|
|