|
I wanted to use only the PrintPreview Feature from the WTL. I think this can also be easily rewritten in MFC. But it was available for a fast test. After I rewrote the problematic line to read:
class CPrintDC : public WTL::CDC
{
}
I could compile my project and everything is running fine.
I was more astonished, that the lookup for typedef is first done in the global namespace and then in the local namespace. I think this is more a question concerning the compiler.
Thanks
Dirk
|
|
|
|
|
Thanks for the info.
John
|
|
|
|
|
Well.. i have got a db - query (in a vector). There is one field, which contains an integer. Now i should find out all the unique numbers and get some kind of index. (based on sorting the unique numbers).
Is it good programming style to do this by using a map (unique number -> index) or is it good if i use a sorted vector and get the index by using distance (begin(), iterator).
any recommandations ?
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
Bernhard wrote:
Is it good programming style to do this by using a map (unique number -> index)
That doesn't strike me as a style question, more of a "is a map the right tool for the job?" question. I'd say yes, Perl guys do this all the time with hashes. And I just did it myself a couple weeks ago - I have a big list of artist/album names and needed to populate a tree that shows all the names that are present. A map worked perfectly for making a list of unique names.
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
CP SearchBar v2.0.2 released
|
|
|
|
|
well.. i think of a vector as some kind of dynamical array. and so it would be no problem, using the distance method. altough this way of doing it leaves a bad taste in my mouth (even after brushing my teeth this morning )
and i have got the feeling, that it might be faster for a big count of items. (which this query doesn't really have)
.. i just wanted to hear any / some opinions on this topic ..
(backing me that a map is a little bit of an overkill.. but maybe the better choice)
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
Hi there,
my requirement is such that i have to have a singleton based exe or dll server. Dll is better choice.
Now when i use the DECLARE_CLASSFACTORY_SINGLETON macro on exe local server no problem happens and i have a singleton allright.
I have done debugging on that and the same object is returned using
CoCreateInstance
now i want to use an inproc server and i want it to be singleton as you know the requirement are but when i debug it there are seperate object formed for each client instance attaching.
and it doesn't care about the macro.
I know that for every process mapping of a dll is done but i want some mechanism of COM which let me have a single instance dll inproc server.
I need a solution to this problem otherwise i have to stick to expensive marshalling.
|
|
|
|
|
Probably, lifetime of the object 1, you created, is not intersecting with lifetime of object 2. Then last reference to COM object released, library were unloaded. Next time Your singleton created againe.
If You still want to use dll and make them really singleton, You should have at least one loaded instance.
But also You can store state of the object on disk, using IPersist* interfaces.
Regards,
Alexander Fedorenko,
Author of DevPlanner - tool for effective planning in development.
mailto:sashaf@arshin.com
|
|
|
|
|
Hi,
this not an answer to your problem, but i'd
like you the read ATL Creators which is very important for singleton objects.
Furthermore, read "Alternative Implementation of ATL Singleton" in MSDN (Q201321).
|
|
|
|
|
Hi,
Using a DLL for the same process you will get the same instance, but for different processes ( exe's), I'm afraid there's no way to do that, the DLL is attached to a process, no way to change that, I tried to make the same thing as you... and smashed on the wall , EXE is slow and bad, but the only way to get a real real singleton on different processes.
Good Luck
Braulio
|
|
|
|
|
Wrong answer!!! It is possible with dlls. Read articles in MSDN about dll nature.
Regards,
Alexander Fedorenko,
Author of DevPlanner - tool for effective planning in development.
|
|
|
|
|
You should never create a DLL singleton. This has been discussed many times
in the past, and I won't recount the reasons why. But if you want to do some
background research, check the archives at http://discuss.microsoft.com, and
do a search for "DLL singleton".
think about a process creating your SINGLETON.
It will lookup the registry that says: load DLL
Then it will ask the DLL to get a ClassFactory for SINGLETON
The factory will create a new object and return it.
Every time to process asks for SINGLETON it get the same object.
That's what singleton means.
But now a second process tries the same.
Will it get the same object from the different adress space ?
I hope not, because of the 0xC0000005 exception you would probably see then
DLL SINGLETON's are only singletons within a process.
Donno, if now something as changed but one year ago... the techies said that...
|
|
|
|
|
Yes... I have been looking now... there is one strange way of doing now... but then you are making not a right thing... something wrong with the architecture of the system...
Greetings
Braulio
|
|
|
|
|
I just wanted to know is it possible or not
and the articles referred to in msdn and internal atl on devx are all for taking care in sta based thing i just want to know that is it possible or not
if it is i need the method. If not then i would look into exe based singleton which i have worked on before and managed it easily.
My conclusion uptill now is that singleton for a dll is like for a proces. I mean to say you can only have one object per process but many for many processes i.e. one for each process.
And for exe base out of process one and only one instance runs in an address space.
So i need a shared memory(dynamic mechanism) between all the process using dll.
|
|
|
|
|
I had the following code:
for_each(pool.begin(), pool.end(), ::ResumeThread);
In this case pool was a vector of handles.
std::vector<HANDLE> pool;
I needed to convert it to a map so here is the new code:
std::map<HANDLE, unsigned int> pool;
So now I wrote the code with a for loop instead.
for(std::map<HANDLE, unsigned int>::iterator it =pool.begin(); it != pool.end();it++) {
::ResumeThread(it->first);
}
My question is how do I do this with a for_each statement?
John
|
|
|
|
|
Unfortunately, you'll need to use the non-standard select1st and compose1 functions (AFAIK). VS.NET 2K3 doesn't support either function out of the box, but other STL implementations do (they are SGI extensions).
Here's an example using GCC 3.x:
<br />
#include <map><br />
#include <algorithm><br />
#include <functional><br />
#include <ext/functional><br />
<br />
using namespace std;<br />
using namespace __gnu_cxx;<br />
<br />
typedef map<int,int> pool_t;<br />
<br />
void Process(int i) {<br />
printf("%d\n",i);<br />
}<br />
<br />
int main(int argc,char **argv) {<br />
pool.insert(pool_t::value_type(1,2));<br />
pool.insert(pool_t::value_type(5,2));<br />
pool.insert(pool_t::value_type(3,2));<br />
pool.insert(pool_t::value_type(2,2));<br />
<br />
for_each(pool.begin(),pool.end(),<br />
compose1(ptr_fun(Process),<br />
select1st<pool_t::value_type>()));<br />
<br />
return 0;<br />
}<br />
Of course, it's a bit dubious as to whether this is really any easier to work with than writing your own iteration loop.
If there's another way to accomplish this without using the extensions, I'd love to know
- Mike
|
|
|
|
|
Thank You for the detailed explanation.
Michael Imamura wrote:
Of course, it's a bit dubious as to whether this is really any easier to work with than writing your own iteration loop.
I agree. The loop looks simpler to me.
Thanks again,
John
|
|
|
|
|
One way to do it is to just write a small wrapper function around ResumeThread that takes a std::pair instead of just a HANDLE
void myResumeThread(const std::pair<HANDLE, int> &pair) {
::ResumeThread(pair.first);
}
int main(int argc, char* argv[])
{
std::map<HANDLE, int> blah;
std::for_each(blah.begin(), blah.end(), myResumeThread);
}
Another alternative, is if you find yourself doing it alot, is to write a really small class to do the wrapping automagically (Which is probably similar to what the other STL implementations would do anyway, but I'm not sure, since I just made this up) :
template <class T, class PAIR>
class FirstWrapper {
public:
FirstWrapper(T f) {
func = f;
}
void operator()(const PAIR &p) {
func(p.first);
}
T func;
};
template <class T, class CONTAINER>
FirstWrapper<T,CONTAINER::value_type> makeFirstWrapper(T func, const CONTAINER &cont) {
return FirstWrapper<T,CONTAINER::value_type>(func);
}
int main(int argc, char* argv[])
{
std::map<HANDLE, int> blah;
std::for_each(blah.begin(), blah.end(), makeFirstWrapper(::ResumeThread, blah));
}
The above code just makes an adhoc function wrapper around whatever function call you need.
The STL extensions suggested in the other post are more flexible, but this would do for this purpose.
Phil
|
|
|
|
|
Thanks a lot. I did not think of that...
John
|
|
|
|
|
Hello there,
I am doing array of stuctures marshalling using a local server i just wanted to know is there any limitation on marshalling or should i allocate 1mb or more of memory on the server side and pass it back.
function is like this on server side
[helpstring("method ")]GetBuddyList HRESULT GetBuddyList( [in] BSTR nick, [out] ULONG* pSize, [out, size_is(, *pSize)] loginInfo** ppBuddyList);
client just passes and empty pointer by reference and size also as empty UINT.
What i mean to say is that it wouldn't crash for very large marshalling of array of structures.
|
|
|
|
|
It shouldn't crash. You need to remember, however, that marshalling in a lot of cases makes copies as the data goes back and forth. It might be better to have the client ask for specific chunks, rather than the entire array at once.
Software Zen: delete this;
|
|
|
|
|
I just wanted to bring it into your notice that me and my friend worked on another dcom project in which server was remote and there it gave an error on more than 200kb of data passage or so. MTU Problem or whatever. Now i am going to try to marshal for local server and i just wanted to confirm that it would work for any array size.
And also could u give me explanation of
"marshalling in a lot of cases makes copies as the data goes back and forth."
|
|
|
|
|
Clients communicating with local servers have to pass data across process boundaries, which requires copying the data (which is what the marshalling process does). Win32 applications have separate address spaces, making the copy operation more complicated than a simple memory to memory copy. The copy operation is slow in this case. You should make sure that this is acceptable for your application. Using smaller amounts of data, while requiring more transactions to pass the same total amount of data, can make the application more responsive overall.
In my experience, almost any size of data can be transferred. In one application, we were transferring 32Mb images between the client and a remote server. While it was slow (several seconds over a dedicated 100 Mbit network), it was fairly reliable.
Software Zen: delete this;
|
|
|
|
|
Thank you i have tried four MB of marshalling no problem so that i am confident that it would work for bigger cases.
And i am thankful for your responsiveness.
regards,
umar.
|
|
|
|
|
Hi, I am planning to start ATL Com programming. Can anybody suggest a good starting point / online tutorial ?
Thanks
|
|
|
|
|
"Inside ATL" from Microsoft Press, it's hard to digest but not a bad book. If you know COM raw programming it will be easy for you, if not... you will enjoy a lot
Greetings
Braulio
|
|
|
|