|
What is the good way to create the coclass object that can take care of reference count.
|
|
|
|
|
Michael Dunn wrote:
CComObject is not a smart pointer class, so any time you create a new reference to the underlying object, you need to AddRef() it.
Ok, not know hardly anything about COM I have a question off this answer. I assume that CComObject is an already wrapped class/object? Otherwise wouldn't you call an AddRef(); function inside your constructor to increment the reference counting? I suppose a more generalized answer to my question would be for me to read more about COM. In due time I suppose.
Nick Parker
You see the Standards change. - Fellow co-worker
|
|
|
|
|
ATL abstracts IUnknown implementation in three classes : CComObject / CComAggObject and CComPolyObject - CComObject provides the IUnknown implementation for non-aggregated objects.
|
|
|
|
|
I have to question:
1- If I chose "yes" in aggregation section of ATL Object Wizard then should a create the coclass object using CComAggObject or CComObject?
2- Do same reference counting rules apply when creating coclass object through CComObject as with interface pointers?
Thanx in advance.
qur
|
|
|
|
|
If you choose "yes" for aggregation then your class can run either standalone or aggregated, so you can use both CComObject or CComAggObject ( depending on your needs). And yes , you will have to take care of the object lifetime, addref-ing and releasing properly any object created by CComObject. However, if you just want to create and use an object inside a function you can use CComObjectStack - it doesn't perform reference counting.
|
|
|
|
|
Can I supress the "look if item is still there", when I insert an item into a map?
(I already verified that the item is not there, and want to save the overhead)
If I could find a souvenir / just to prove the world was here [sighist]
|
|
|
|
|
One solution is a multimap since it allows multiple same elements by design, thus I doubt there is a lookup.
Kuphryn
|
|
|
|
|
The "look if the item is there" is just a byproduct of finding the correct insertion point, so can't really be removed...personally, I wouldn't bother verifying that the item's not in the map, I do something like this:
std::pair<iterator, bool> insertionResult = map.insert(std::make_pair(key, value));
if (!insertionResult.second) insertionResult.first->second = value;
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Stuart Dootson wrote:
is just a byproduct of finding the correct insertion point
good point, it's probaly a silly question.
I have to check if the item is in the map before, it's an "overwrite or add" operation, which needs additional housekeeping if it's an overwrite.
If I could find a souvenir / just to prove the world was here [sighist]
|
|
|
|
|
maps overwrite by default. IIRC, the return value is a map<T>::value_type which means you can examine what was overwritten.
--
Only in a world this sh*tty could you even try to say these were innocent people and keep a straight face.
|
|
|
|
|
There's a version of std::map::insert that accepts an iterator as a hint to the appropriate insertion place. You can take advantage of this if you previously save the position of the immediately preceding element in the map, as the following example shows:
#pragma warning(disable:4786)
#include <map>
using namespace std;
template <class map_type>
map_type::iterator insert_if_not_present(map_type& m,const map_type::value_type& v)
{
map_type::iterator it=m.lower_bound(v.first);
if(it!=m.end()){
if(!m.key_comp()(v.first,it->first)){
return it;
}
}
if(it!=m.begin())--it;
return m.insert(it,v);
}
int main(void)
{
map<int,int> m;
insert_if_not_present(m,make_pair(1,1));
insert_if_not_present(m,make_pair(2,2));
insert_if_not_present(m,make_pair(3,3));
insert_if_not_present(m,make_pair(2,2));
return 0;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
hi,
I'm developing ATL ActiveX EXE server that runs as a Window services using ATL wizard.
This server contains one ATL object (CTest).
How I can set the server so that when it started (via Window Services Applet), the server will :
1) initiate/create CTest.
2) Call method/function in this ATL object (CallMe).
3) destroy CTest when server stopped.
Thanx in advance.
Regards.
|
|
|
|
|
Hi.
How do you definte a comparison function for an container of std::pair other than map? I need to search a container of std::pair. For example:
typedef std::deque<std::pair<std::string, int=""> > deqStringInt;
deqStringInt example;
example.push_back(std::pair<"December", 21>);
// How do you search an element?
std::find_if(example.begin(), example.end(), std::bind2nd(???
// Functor
class Search : std::binary_function<std::pair<std::string, int="">, std::string, bool>
{
public:
bool operator()(const std::pair<std::string, int=""> &lp, const std::string &rp)
{
return lp->first == rp;
}
};
Thanks,
Kuphryn
|
|
|
|
|
#pragma warning(disable:4786)
#include <queue>
#include <string>
#include <algorithm>
typedef std::deque<std::pair<std::string,int> > deqStringInt;
struct my_search
{
my_search(const std::string s):s(s){}
bool operator()(const std::pair<std::string,int>& c) const
{
return c.first==s;
}
private:
std::string s;
};
int main(void)
{
deqStringInt example;
example.push_back(std::make_pair(std::string("December"), 21));
std::find_if(example.begin(),example.end(),my_search("December"));
return 0;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Nice! Thanks.
Here is another solution and the one I implemented.
class Searc : std::binary_function<pairstringint, std::string,="" bool="">
{
public:
bool operator()(const pairStringInt &lp, const std::string &rp) const
{
return (lp.first == rp);
}
};
std::find_if(data.begin(), data.end(), std::bind2nd(Search(), theString))
Kuphryn
|
|
|
|
|
Hi.
Is it possible to have an unsorted map and/or multimap STL container? The map is an extremely useful STL container because of its key and value feature. I need to set a map container to not sort its keys, i.e. insert them if they do not exist, but in a queue fashion as in FIFO.
Thanks,
Kuphryn
|
|
|
|
|
Just combine the key and value into another structure/class or use std::pair and then use std::deque as your container. It works well as a FIFO where as by definition, a map is sorted and would perform poorly as a FIFO.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Nice! Thanks
Can you give a quick example of std::pair in other containers beside the map? I did not know it was possible to use std::pair as a datatype. How about searches?
Kuphryn
|
|
|
|
|
No. You want vector<< pair <type1, type2 > >
A map cannot deliver it's performance guarentees if it does not sort the values.
A hash map might, I'm not sure.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Nice! Does search works for std::pair as map's std::pair? In other words, do you have to write a special search algorithm to find an element in std::vector<std::pair<t, u=""> >?
Kuphryn
|
|
|
|
|
You can't use [] on a vector in that way ( you can by providing a numeric index ), but you can write a functor to find based on the first element, yes.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
|
hi all,
i am stuck. I want to make a setup for my VC application as we have in VC. But can't find anything helpful.
if anyone can suggest me anything would be a great help.
thanks in advance
Himanshu
|
|
|
|
|
There is a large variety of setup toolkits to fit any budget. We use Wise InstallBuilder but there are a number of lower-cost options as well. For example take a look at InnoSetup. For a list of others, visit any popular download site such as download.com or tucows.com.
-Anatoly
Anatoly Ivasyuk is co-founder of DTLink Software, a company specializing in Internet software and technologies. He is the author of DTLink's Windows products: AnswerTool, FAQTool, AppUpdate, and Personal Stock Monitor
|
|
|
|
|
hi~
I apologize being not good at English.
I wanna serialize my own data for network/file/etc...
I thought that stream of c++ standard library is suitable.
but, there's no facilities exactly for my use.
1. I wanna store stream data into memory.(not file)
2. insertion and extraction must operate in binary mode.
// example of usage
// proc A
omystream ms; // mystream is that I wanted..
int n = 1;
short s = 2;
ms << n << s;
// or ms << int_b(n) << short_b(s);
// int_b(), short_b() is custom manipulators
::send(ms.buf(),...); // send to network
// proc B
BYTE buf[4096];
::revc(buf,...); // receive from network
imystream ms(buf, dwSizeReceived); // dwSizeReceived = 6
int n;
short s;
ms >> n >> s; // n = 1, s = 2
// or ms >> int_b(n) >> short_b(s);
// result
data occupy 6 bytes memory. (4 for n(int), 2 for s(short))
send and receive 6 byte of memory.
memory layout:
00 00 00 01 00 02 // 6 byte
not
"000000010002" // 12 byte
this mean not string but binary.
how can I achieve it?
derive strstream or stream?
derive stream_buf?
I need your advice.
thanks in advance.
|
|
|
|