|
garyflet wrote: How does the server know which clients, if any, are still attached?
I may be misinterpreting your question, but this is done by reference counting.
The server will in general not know anything about its clients, it only knows that it has one or more clients attached to it.
garyflet wrote: When my automation client calls COleDispatchDriver::ReleaseDispatch(), thus releasing the server, the server receives a WM_CLOSE message. If there are other clients still connected, the server,if visible, is supposed to display a message to that effect and offer to close.
From your question I assume you're talking about an application that runs as an out-of-process COM server. I wouldn't expect the server to close, or even the WM_CLOSE message being sent, unless the reference count reaches zero. Popping a dialogue asking the user whether to shut down the server or not seems a bit odd since there shouldn't be any clients left.
garyflet wrote: If invisible, the server simly doesn't close.
Don't quite get what you mean by this, but when a server shuts down and calls ::CoUninitialize it tries to dispatch all pending COM calls in a message loop. A server may hang inside this loop if the server hasn't released all COM servers it may have created.
Your problem may be related to this, or it may be popping an invisible dialogue box waiting for user input.
I think you need to explain your problem a bit further and what you're trying to do.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Thanks very much for your reply.
Roger Stoltz wrote: I may be misinterpreting your question, but this is done by reference counting.
The server will in general not know anything about its clients, it only knows that it has one or more clients attached to it.
That's exactly my question. I don't know how to do reference counting! My MDI server has a CCmdTarget derived class: CAutoApp. I noted that CAutoApp gets created with every new client connection, so I put in an array to capture the LPUNKNOWN return from GetInterface(&IID_IUnknown). However, I still don't know how to use that to tell me if the client has disconnected.
Roger Stoltz wrote: From your question I assume you're talking about an application that runs as an out-of-process COM server. I wouldn't expect the server to close, or even the WM_CLOSE message being sent, unless the reference count reaches zero. Popping a dialogue asking the user whether to shut down the server or not seems a bit odd since there shouldn't be any clients left.
After any client calls ReleaseDispatch(), my server gets a WM_CLOSE message whether or not there are any clients left. I wouldn't even have to do a reference count if this were not the case. Maybe that's the real question, why do I get a WM_CLOSE message even when there are clients left? I'm not sure how to investigate that.
|
|
|
|
|
garyflet wrote: My MDI server has a CCmdTarget derived class: CAutoApp. I noted that CAutoApp gets created with every new client connection
Well, I consider this a strange behaviour because this means that there con be only one client per CAutoApp instance. The reference counting seems to be put aside.
If you override OnFinalRelease in your CCmdTarget derived class and put a breakpoint there, I assume it will get hit when any of the clients "disconnects", but for different CAutoApp instances. I assume that the WM_CLOSE message will be sent from the same call chain.
I suspect you're using the CCmdTarget derived class in a way it wasn't intended.
When a new client "connects" the reference count should be increased for the same object, i.e. the m_dwRef member of your CAutoApp object should be increased by one. But this apparently does not happen, instead you're creating a new instance of the class which sounds strange.
garyflet wrote: After any client calls ReleaseDispatch(), my server gets a WM_CLOSE message whether or not there are any clients left.
I would expect that since the reference count for the instance reaches zero. When the one and only client to the CAutoApp object "disconnects" the object will be destroyed.
garyflet wrote: why do I get a WM_CLOSE message even when there are clients left?
That's the thing: there are no clients left for that CAutoApp instance.
I suspect a design flaw here, but I cannot tell since I don't have enough information. It might require the complete source code and dig into it.
It sounds like the CAutoApp class should be a singleton since it appears to control the lifetime of the entire application, but you've created multiple instances of it. When one of the instances reference count reaches zero it wants to close the application, hence the WM_CLOSE message.
My best tip is to re-evaluate your design.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
what this error means?
#include "strutil.h" No such file or directory
|
|
|
|
|
It means the file strutil.h does not exist in the location you told the compiler to look for it.
led mike
|
|
|
|
|
how look for it
modified on Friday, June 27, 2008 1:11 PM
|
|
|
|
|
What about the documentation [^]?
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]
|
|
|
|
|
|
You can search for this file on your computer.
|
|
|
|
|
I would like to write an exchange add-in that will process messages before they are delivered to user mailboxes. Can someone tell me if this is possible and, if it is, tell me the name of the add-in technology so I can search for some examples. I'm getting nowhere fast guessing?
|
|
|
|
|
|
Hi,
Can any once help me in removing the tab spaces using c++ source.
I am reading a text file line by line and i am able to remove all the spaces, but i am unable to reomve the tab spaces.
Thanks,
Nandu
|
|
|
|
|
Removing '\t' character should be similar to removing ' ' one.
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]
|
|
|
|
|
Even i tried with '\t', but still i am facing the same problem.
string removeSpaces( string & str )
{
std::string::iterator to = str.begin();
std::string::iterator from;
for( from = str.begin(); '\0' != *from; ++ from )
{
if ( (' ' != *from ) || ('\t' != *from))
*(to ++) = *from;
}
if( *to != '\0' )
str.erase(to, from);
*to = '\0';
return str;
}
|
|
|
|
|
Nandu_77b wrote: if ( (' ' != *from ) || ('\t' != *from))
Don't you think it should be &&
Can anyone confirm??
Regards,
Sandip.
|
|
|
|
|
SandipG wrote: Nandu_77b wrote:
if ( (' ' != *from ) || ('\t' != *from))
Don't you think it should be &&
Can anyone confirm??
Absolutely.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
It can't be && as I am reading char by char only one value will be there at one point of time.
|
|
|
|
|
It should be && because you neither want space nor tab.
Consider following cases with your current condition.
1>char 'a'
if(' '!='a' this condition will evalute to true so it wont even check next contition and it wil execute if block.
2 char ' ' space
here,
if(' ' != ' ' will evaluate false so it will go and check next condition i.e '\t' != ' ' which is true so again it will execute if block.
same applies for '\t' only firt condition will be executed and after that if block will be executed.
so in every case your if block will be executed
I hope now it makes sense.
Can anyone confirm if this is correct?
Regards,
Sandip.
|
|
|
|
|
Even i tried with '\t', but still i am facing the same problem.
string removeSpaces( string & str )
{
std::string::iterator to = str.begin();
std::string::iterator from;
for( from = str.begin(); '\0' != *from; ++ from )
{
if ( (' ' != *from ) || ('\t' != *from))
*(to ++) = *from;
}
if( *to != '\0' )
str.erase(to, from);
*to = '\0';
return str;
}
I have tested with && ...it is not working
|
|
|
|
|
Can you paste with your sample string for which it is failing?
Regards,
Sandip.
|
|
|
|
|
Nandu_77b wrote: string removeSpaces( string & str )
{
std::string::iterator to = str.begin();
std::string::iterator from;
for( from = str.begin(); '\0' != *from; ++ from )
{
if ( (' ' != *from ) || ('\t' != *from))
*(to ++) = *from;
}
if( *to != '\0' )
str.erase(to, from);
*to = '\0';
return str;
}
change to
string removeSpaces( string & str )
{
std::string::iterator to = str.begin();
std::string::iterator from;
for( from = str.begin(); str.end() != from; ++from )
{
if ( (' ' != *from ) && ('\t' != *from))
*(to++) = *from;
}
if( to != str.end() )
str.erase(to, from);
}
as others pointed out, the main flaw is the || operator instead of the && one.
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]
|
|
|
|
|
As advised earlier by SandipG and cPallini, you have to replace the OR-operator (||) with an AND-operator (&&).
It does work.
However, what doesn't work is when the iterator reaches the end of the string; you'll get an assertion. If this is your new problem it would help if you mentioned that.
Try putting what you're trying to do in words, almost as psuedo-code.
This approach will make you write more understandable and intuitive code, which will make things easier for you and others that have to read your code.
I set the insert location and the current location to the beginning of the string.
Until I've reached the end of the string I continue to...
Check if the current char is a space or a tab and if it is, I skip the char, otherwise I copy the char to the insert location.
In code it would look something like this:
std::string& removeSpaces( std::string& str )
{
std::string::iterator to = str.begin();
std::string::iterator from = to;
while( from != str.end() )
{
if( (*from == ' ') || (*from == '\t') )
{
++from;
}
else
{
*to++ = *from++;
}
}
if( to != str.end() )
{
str.erase( to, from );
}
return str;
}
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I used bitmaps for toolbar buttons.
Now I need to use background transparent images for those buttons.
I have the background transparent GIF images.
Can I obtain background transparent BMPs?
How can I use the GIFs for the toolbar buttons?
danginkgo
|
|
|
|
|
I can answer part of your question, at least.
If you look at the docs for LoadImage, one of the flags is:
LR_LOADMAP3DCOLORS, which replaces set colours with your systems (eg) dialog face colour.
Alternatively, ImageList_AddMasked has a "treat this colour as transparent" option you could uses. So, you could make a bitmap using bright pink as the background, then use that as transparent.
Assuming you're not making a Barbie themed app, of course...
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Thanks, I'll try
danginkgo
|
|
|
|