|
Anyone know why the .push_back function for a vector would overwrite the last entry. So for example, if i push 10 items into the vector. When i am done, the vector size shows 10 but the only item in there is the last one. I am totally clueless on this.
I call this function in a dll:
DLL_API int GetDATA(std::vector<datainforecname*>& pVectorDataInfoRecName, std::string sPath )
Then i process a DataInfoRecName pointer.
_tcscpy( pDataInfoRecName->szDate, TempString.c_str ());
Then i push it into the vector
pVectorDataInfoRecName.push_back(pDataInfoRecName);
|
|
|
|
|
Hello All!
I am newbie in ATL/COM programming, so I have tried to firing events based on this article
http://www.codeproject.com/atl/SimpleATLCom.asp for VC 2005 final.
I put the following code to the .h file
<br />
[<br />
dispinterface,<br />
nonextensible,<br />
hidden,<br />
uuid("DEEA616A-2B80-4965-9A31-2F67B704EB70"),<br />
helpstring("_ISimpleObjEvents Interface")<br />
]<br />
__interface _ISimpleObjEvents<br />
{<br />
[id(1), helpstring("method TotalMarks")] HRESULT TotalMarks([in] SHORT TotalMark);<br />
};<br />
...<br />
<br />
<br />
[<br />
...<br />
event_source(com),<br />
...<br />
]<br />
class ATL_NO_VTABLE CSimpleObj :<br />
public ISimpleObj<br />
{<br />
...<br />
__event __interface _ISimpleObjEvents;<br />
...<br />
}<br />
And trying to rise event
like this:
<br />
__raise TotalMarks(TotalMark);<br />
In my basic client I am trying to catch event like this:
<br />
Private Sub Obj_TotalMarks(ByVal TotalMarks As Integer)<br />
'Display the MessageBox displaying Total Marks<br />
MsgBox("total marks " & TotalMarks)<br />
End Sub<br />
Help me please, where I am wrong?
|
|
|
|
|
|
Thanks a lot, the problem was resolved by adding the "Handles Obj.TotalMarks" at the end of Obj_TotalMarks subroutine definition:
Private Sub Obj_TotalMarks(ByVal TotalMarks As Integer) Handles Obj.TotalMarks
|
|
|
|
|
I want to send and receive object to an ATL COM object. For example I create following classes
Input (IInput)
Output (IOutput)
RunP (IRunP)
Input has an (BSTR) attribute named "m_input" and Output has an (BSTR) attribute named "m_output". Also RunP has a method named "process" it gets an IInput object and returns IOutput object.
I assign a string to m_input from C# code. Then I print the m_input with MessageBox. But the program stops running and gives following errors
"Run-Time Check Failure #3 - The variable 't' is being used without being defined"
AccessViolationException
It gives the error in get_m_input line.
STDMETHODIMP CRunP::process(IInput* inp, IOutput** outp)
{
BSTR* t;
inp->get_m_input(t);
MessageBox(NULL, *t, L"asd", 0);
return S_OK;
}
I can't find the problem. Is there any documentation that explains how to send and receive objects from a ATL COM object.
Thanks
|
|
|
|
|
xelontr wrote: BSTR* t;
inp->get_m_input(t);
Probably, this function is expecting variable with memory allocated, modify this code to this and try,
BSTR t;
inp->get_m_input(&t);
|
|
|
|
|
I want to store a group of employee objects in an array or collection of some type and then be able to find which employees are of a certain department number. For example there may be a total of 10 employees with 4 of the employees belonging to department 1 and the rest to various other departments, I want to be able to find all of the employees belonging to department 1 and print those out. What do you think is the best way to do this? I tried to use a vector sequence container, but I don't know how I would find multiple employee objects depending on dept number attribute.
Any help would be greatly appreciated,
Jason
|
|
|
|
|
You could have a map containing vectors. The map key would be the department number, and the data would be a vector (or better, a pointer to a vector) of employees.
Steve S
Developer for hire
|
|
|
|
|
But what if there were multiple map key's (department number's) that are the same? It would only show the first occurance, right? Is there a way I can show all objects of that same key?
Thanks,
Jason
|
|
|
|
|
Do you mean that there are multiple departments with the same number, or that there are multiple employees in the same department?
If the former, then you cannot use department number as a key, since you cannot be sure which distinct department you should be referring to.
If the latter, that's why the data is a vector, so you can add multiple employees.
Steve S
Developer for hire
|
|
|
|
|
The latter, multiple employees in the same department. How would I use a vector inside of a map? I tried the following example but received an error C2665 'std::pair<_Ty1,_Ty2>::__ctor' : none of the 3 overloads can convert parameter 2 from type 'const char [5]'
<code>
typedef map<int, vector<string> > EmployeeType;
void MapVectorTest()
{
EmployeeType theMap;
EmployeeType::iterator theIterator;
theMap.insert(EmployeeType::value_type(0, "Zero")); // error C2665
}
</code>
-- modified at 14:43 Friday 2nd March, 2007
Thanks,
Jason
-- modified at 14:48 Friday 2nd March, 2007
|
|
|
|
|
A multimap will allow you to have multiple values per key.
Dave
|
|
|
|
|
I am reading from a file after opening using this command
ReadFile(hFile,&strData, 300, &dwbytes, NULL); in a C++ dll
strData is defined as a std::string
say std::string test = strData;
After executing the above command, i get an error .. something about misaligned string. I am not sure what could be going on here. When i debug and watch the values i see strData as {???} but then when i drill down, i actually see the correct data read from the file, but it seems like something is wrong such that strData cannot be accessed
|
|
|
|
|
Windows APIs know nothing about C++ objects. You have to pass ReadFile() an array of BYTE s, then take that data and put it in a string .
|
|
|
|
|
I want to write a specialization of the map-class. I just want to synchronize access to the map in memory, the rest should stay the same. Is there any way to achieve that without completely rewriting the class ? Maybe something like accessing the 'base-class'-method ?
|
|
|
|
|
Got it ! I just have to create a custom map that internally keeps a STL-map. Then i can implement all the functions i need and wrap synchronization around them. It's just too simpel.
|
|
|
|
|
Hi All
I m working on a ATL project. There are a lot of warnings as
warning C4653: compiler option 'Optimizations (one or more of /Oawstgp[y]) or debug checks (one or more of /GZ, /RTCcsu)' inconsistent with precompiled header; current command-line option ignored
warning C4651: '/D__MSVC_RUNTIME_CHECKS' specified for precompiled header but not for current compile
Can anybody describe why it is?
Thanks
Pankaj Jain
|
|
|
|
|
Sounds like you've changed compiler options somehow - do a Build->Rebuild - that should do it.
|
|
|
|
|
Hi All
I m working on a ATL Project. I have to add string in a multi column List box using SendDlgItemMessage() but I dont get any idea about that.
I m using it like this
SendDlgItemMessage(IDC_LIST1, LB_INSERTSTRING, (WPARAM) 0, (LPARAM)"Hi");
SendDlgItemMessage(IDC_LIST1, LB_INSERTSTRING, (WPARAM) 1, (LPARAM)"All");
But it is not working. I want to Add "Hi" in one column and "All" other.
If u have any Idea Please suggest me
Thanks & Regards
Pankaj Jain
|
|
|
|
|
PK Jain wrote: But it is not working.
What is exact problem ?
PK Jain wrote: I want to Add "Hi" in one column and "All" other.
WPARAM value refers to item index, not column index.
|
|
|
|
|
Thanks,
But my query is not solved
How to Add String in MultiColumn ListBox using SendDlgItemMessage
Pankaj Jain
|
|
|
|
|
PK Jain wrote: But my query is not solved
For that you need to answer questions asked. I asked, what do you mean by not working ?
PK Jain wrote: How to Add String in MultiColumn ListBox using SendDlgItemMessage
Same as you written in in your original post.
I think you mistaken multicolumn with number of columns as in list box. In case of list box, multi column means, there will be no vertical scrolling as number of string keeps increasing.
Instead, string will be added to next column and so on, and horizontal scroll bar will appear.
I hope this clear your doubts.
|
|
|
|
|
Thanks Prasad,
Thanks to clear my doubts
Pankaj Jain
|
|
|
|
|
A MultiColumn ListBox doesn't give that functionality - you want a ListView instead. To add text to a ListView in the way you want, use something like:
LVCOLUMN col = {0};
SendDlgItemMessage(IDC_LIST2, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
col.iSubItem = 1;
SendDlgItemMessage(IDC_LIST2, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
LVITEM item = {0};
item.mask = LVIF_TEXT;
item.iSubItem = 0;
item.pszText = "Hi";
int itemIndex = (int)SendDlgItemMessage(IDC_LIST2, LVM_INSERTITEM, 0, (LPARAM)&item);
item.iSubItem = 1;
item.pszText = "All";
SendDlgItemMessage(IDC_LIST2, LVM_SETITEMTEXT, itemIndex, (LPARAM)&item);
SendDlgItemMessage(IDC_LIST2, LVM_SETCOLUMNWIDTH, 0, LVSCW_AUTOSIZE);
SendDlgItemMessage(IDC_LIST2, LVM_SETCOLUMNWIDTH, 1, LVSCW_AUTOSIZE);
[Updated to correct code, add column sizing]Last modified: 17mins after originally posted --
|
|
|
|
|
Hi All,
I use AllocSysString like this
1) - CString myStr="ABCD";
int i=SomeFunction(myStr.AllocSysString());
Later in the code I free the memory as SysFreeString(_com_util::ConversStringToBSTR(myStr));
After using a memory profiling tool now, I don't get a mem. leak in this manner.
Is this the correct approach or should I use
2) - CString myStr="ABCD";
BSTR myStrBSTR=myStr.AllocSysString();
int i=SomeFunction(myStrBSTR);
and then use SysFreeString. While googling I found out the use of CComBSTR.
Can someone here tell me if I am using the right approach or should I use the second one, or use CComBSTR that manages allocation/deallocation by itself.
|
|
|
|