|
My vector is losing data when I "push_back" my class of CStrings. In "debug", before the "push_back" I can plainly see that the class has all the data in it. When I "push_back" the class into the vector, the class still has the data but the vector( in debug) does not have all the data. Does anyone know why this would happen?
VS2008 Pro, MFC.
A C++ programming language novice, but striving to learn
|
|
|
|
|
What exactly are you adding to the vector, a CString object, pointer or reference?
Have you tried using CStringArray instead?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Could you please post (a piece of) your code?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Here's the heaer for for the class I'm inserting into the vector:
// WellSysData.h : header file
// Class's Used by: CWellSysDlg,
#pragma once
// CWellSysData
// Class that contains the WellSystem File Data
class CWellSysData
{
public:
// Functions:
CWellSysData(); // Default Constructor
~CWellSysData(); // Default Destructor
void CleanUp(void);
// Copy Constructor:
CWellSysData(const CWellSysData& cSource);
// Assignment operator:
CWellSysData& operator= (const CWellSysData& cSource);
CString SetPathName(CString str);
//Varables:
CString m_csOperator;
CString m_csWellName;
CString m_csTankMFG;
CString m_csTankID;
CString m_csDaysPrsent;
CString m_csTankPath;//Path to Tank: \\m_csTankMFG + \\m_csTankID
CString m_csWellPath;//Path to well: \\Operators\\m_csOperator\\m_csWellName
CString m_csExtra1; // WellPath to Well's Data File
CString m_csExtra2;
};
here's the declaration for the vector:
// WellSysDataVec.h
#pragma once
#include "WellSysData.h"
#include <string>
#include <vector>
#include <algorithm>
class CWellSysData;
using std::vector;
using std::copy;
using std::iterator;
using std::string;
class CWellSysDataVec {
public:
CWellSysDataVec(void);
~CWellSysDataVec();
// Varables:
CWellSysData m_cWellSysData;
// Setup vectors:
std::vector<CWellSysData> m_vWellSysData; // vector
std::vector<CString> m_vFileStr; // vector
// Iterators:
std::vector<CWellSysData>::iterator m_ITWellSysData;
std::vector<CString>::iterator m_ITFileStr;
//Functions:
};
Here's the call:
CString str, str2, str3, str4;
CEdit* pEdit1 = (CEdit*) GetDlgItem(IDC_WELLNAME);
str = "";
str3 = "";
str4 = "";
str4 = m_csOperator;
pEdit1->GetWindowText(str);
m_cSysData.m_csWellName = str;
str2 = str;
str3 = str;
str = "";
str2 = SetWellPath(str4,str3);
m_cSysData.m_csWellPath = str2;
str2 = "";
str2 = SetWellFileNamePath(str4,str3);
m_cSysData.m_csExtra1 = str2;// has value in it at this point
str = m_cSysData.m_csWellPath;
m_vSys.m_vWellSysData.push_back(m_cSysData);// m_vWellSysData[0].m_csExtra1 does NOT have the value in it.(ALL OTHER DATA IS THERE. m_cSysData.m_csExtra1 HAS ALL THE DATA IN IT AT THIS POINT AND AFTERWARDS.
CString CCreateWellsDlg::RetWellFileNameSys(CString str4, CString str3)
{
CString str,str1,str2;
str2 = "\\";
str1 = "c:\\Frac Tanks\\Program\\DataBases\\OperatorDB\\Operators\\";
str = str1;
str += str4;
str += str2;
str += str3;
return str;
}
CString CCreateWellsDlg::SetWellFileNamePath(CString str4, CString str3)
{
CString str, str1, str2;
str1 = "c:\\Frac Tanks\\Program\\DataBases\\OperatorDB\\Operators\\";//Operator.sdb");
// Make path for SystemDB.sdb file for each Operator:
str = str1;
str += str4;
str += "\\";
str += str3;
str += "\\";
str += "WellDataDB.sdb";// each Well has this for FracTank Listing
return str;
}
CString CCreateWellsDlg::SetWellPath(CString str4, CString str3)
{
CString str, str1, str2;
str1 = "c:\\Frac Tanks\\Program\\DataBases\\OperatorDB\\Operators\\";//Operator.sdb");
// Make path for SystemDB.sdb file for each Operator:
str = str1;
str += str4;
str += "\\";
str += str3;
return str;
}
A C++ programming language novice, but striving to learn
|
|
|
|
|
Please use code block button to surround the code snippet with <pre> tags.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I found the error here:
When I initialize the copy constructor I left out the m_csExtra1 and m_csExtra2 varables so naturally it couldn't copy them!.
Thanks anyway.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Hello everyone,
Sorry for asking this simple question. I found after some coding, I have some new understanding of the concept. Now I think dual interface means the com object inherits from IDispatch, and since IDispatch inherits from IUnknown, the COM consumer could choose to use IDispatch or IUnknown, so called dual interface.
For non-dual interface, I think it means the com object only implements interface IUnknown.
My understandings are both correct?
thanks in advance,
George
|
|
|
|
|
Dual interface refers to supporting both IDispatch and a VTBL, which means you can call it through COM using QueryInterface or from C++ directly. Been so long since I've done it, I'm a bit fuzzy on the details.
- S
50 cups of coffee and you know it's on!
A post a day, keeps the white coats away!
|
|
|
|
|
Thanks Steve,
I.
Does it means 1 or 2?
1. my coclass implements IDispatch directly, is my coclass dual-interface?
2. my coclass implements some customized interface, and the customized interface implements IDispatch, is my coclass dual-interface?
II.
My confusion is dual means (IDispatch/IUnknown) or (IDispatch/customized interface)?
regards,
George
|
|
|
|
|
Hi George,
Read this link about implementing Dual interfaces. I think things shoudl be clear after this.
Dual Interface[^]
George_George wrote: My confusion is dual means (IDispatch/IUnknown) or (IDispatch/customized interface)?
I think dual interface does not mean two interfaces its about the ways you can access methods.
I hope it helps..
Regards,
Sandip.
|
|
|
|
|
Thanks Sandip,
1.
I have read it. But still confused. Does it mean if my coclass implements IDispatch directly, my coclass is a dual interface?
2.
Two ways to access (dual), you mean one way of using IDispatch and the other way of using IUnknown? Or something else?
regards,
George
|
|
|
|
|
George_George wrote: Two ways to access (dual), you mean one way of using IDispatch and the other way of using IUnknown? Or something else?
No i Think
1. Add an entry (or entries) to the COM map to expose the dual interface through QueryInterface.
2. Implement the vtable part of the interface in your class.
George_George wrote: I have read it. But still confused. Does it mean if my coclass implements IDispatch directly, my coclass is a dual interface? Smile
If you implement the second step in your class..
Does it help..
Regards,
Sandip.
|
|
|
|
|
Thanks Sandip,
1.
I am still confused. Dual interface means two ways to invoke methods of my class. One of them is through IDispatch.Invoke, the other way is?
2.
Confused about what do you mean -- "Implement the vtable part of the interface in your class."
If my class have virtual methods, it should have vtable, what do you mean implement the vtable part?
regards,
George
|
|
|
|
|
George_George wrote: 1.
I am still confused. Dual interface means two ways to invoke methods of my class. One of them is through IDispatch.Invoke, the other way is?
Via another interface's VTABLE .
George_George wrote: 2.
Confused about what do you mean -- "Implement the vtable part of the interface in your class."
Suppose you have (only) a method (say Add ) you can use via IDispatch::Invoke . Implement the VTABLE part of the interface means: provide an interface, say IOperation exposing the Add method (since such method is not directly exposed by IDispatch ).
Possibly the final COM component interface inherits both from IDispatch and IOperation , as Sandip I don't remember the technical details and, as usual: "this in going on my arrogant assumptions..."
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks CPallini,
I have did more study and I want to share my points here. Could you help to
review whether my points are correct please?
1. If a component implements IDispatch directly, we can only invoke its
member methods through IDispatch.Invoke -- only one way, so it is not dual
interface;
2. If a component implements IUnknown directly, we can only use
AddRef/Release/QueryInterface, it is useless since we can only use the 3
methods;
3. If a component implements a customized interface, then the customized
interface implements IUnknown, then we could invoke the component's member
methods through QueryInterface to get the customized interface, and using the
vtable in the customized interface to invoke member methods. But still one
way, so it is not dual interface;
4. If a component implements a customized interface, then the customized
interface implements IDispatch, then we could invoke the component's member
methods through QueryInterface to get the customized interface, and using the
vtable in the customized interface to invoke member methods, and also we
could invoke through IDispatch.Invoke. Two ways to invoke it, so called dual
interface.
All of my understandings are correct? Anything missing?
regards,
George
|
|
|
|
|
IMHO your understandings are correct.
Point (2), as it stands, IMHO is misleading: since IUnknown implementation is mandatory, I will say: if a component implements only IDispatch ...
But such a point is obvious.
Also, as you know well, IDispatch , like any other COM interface must provide IUnknown , then saying: "implementing only IDispatch" it is equivalent to say: "implementing a IUnknown whose QueryInterface method may return only IDispatch ".
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
When you say a component implements IDispatch or IUnknown im assuming that you have an interface IX that is derived from either of those interfaces (IDispatch or IUnknown)and you are implementing those intrefaces in a coclass.
1. Any COM interface has to be derived from IUnknown. So when you implement IDispatch you also have to implement IUnknown, because IDispatch is also derived from IUnknown.
Any interface,say IX, that is derived from IDispatch is a dual interface. Because IX methods can be invoked through IDispatch methods as well as vtable.
2. You can also derive your interface IX from IUnknown and invoke its methods through vtable.
3,4. Don't know what you mean by customized interface.
May i suggest that you go through "Inside COM" by Dale Rogerson. It is a very good book it will help you in understanding COM much better.
|
|
|
|
|
Thanks sw@thi,
1.
You mentioned twice about "invoke its methods through vtable". My confusion is what exactly mean "through vtable". I think you mean QueryInterface for interface IX for the coclass object, and invoke the exposed methods in IX is through vtable of coclass object for interface IX. Correct?
2.
sw@thi wrote: 3,4. Don't know what you mean by customized interface.
Customized interface I mean any C++ eligible interface which is not IDispatch and IUnknown, and in 3 the customized interface inherits IUnknown and in 4 the customized interface inherits IDispatch. From my description, do you think my points for 3 and 4 are both correct?
regards,
George
|
|
|
|
|
Hi CPallini,
I am not sure that we require an extra Interface. Check this Link Dual Interfaces[^]
I could not find some good sample for this do you have one which will explain step by step procedure.. I am asking for this because i have never implemented this ..
CPallini wrote: Sandip I don't remember the technical details and, as usual: "this in going on my arrogant assumptions..."
Smile
Regards,
Sandip.
modified on Friday, September 12, 2008 4:31 AM
|
|
|
|
|
I think you're right, since you may simply do something like:
class IMyDualInterface : public IDispatch
with a VTABLE arranged the following way:
- QueryInterface methods
- IDispatch methods
- 'Add' method here.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks CPallini,
I am a little losing the context and my English is not very good.
Do you guys mean in order to implement a dual interface,
- we need an additional customized interface, which implements IDispatch?
- or we need implement both an additional customized interface (and the customized interface inherits from IUnknown) and also implement IDispatch?
- or both the above two ways are fine?
regards,
George
|
|
|
|
|
We need a customized interface that implements (also) IDispatch (Usually it inherits from IDispatch , that in turn, inherits from IUnknown ).
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi CPallini,
I didn't find any simple article or example to do this on CP, which will explain steps.
Do you know any?
If not i think George can write one side by side as he implements Dual Interface
Regards,
Sandip.
|
|
|
|
|
I am also asking for this, about various ways to implement dual interface.
regards,
George
|
|
|
|
|