Re: ATL COM server for System Tray Icon

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thx...I got it working.
Albert
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:utlKxbQCHHA.4060@xxxxxxxxxxxxxxxxxxxxxxx
The source code got mangled, but I spotted a call to Sleep in there. This
is a big no-no for a single-threaded apartment (which you joined when
calling CoInitialize). You need to run a message pump instead - see
GetMessage, DispatchMessage (yes, console applications can have a message
pump).
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Albert Gomez <albertg@xxxxxxxxxxxx> wrote:
I am trying to get a system tray icon to animate from a console
application. I am using the example from codeproject:

http://www.codeproject.com/atl/system_tray.asp?forumid=4142&select=1759154&df=100&msg=1759154

The example works fine from the user app supplied in the source code.
Since my app is a console project, I attempted to build a very
rudimentary
console application that calls directly into the interface:

// systemtraydemoclient.cpp : Defines the entry point for the console
application.
//

#include <iostream>
#define INITGUID
#include <objbase.h>
#include "SystemTrayDemo.h"

int main(int argc, char* argv[])
{

std::cout<<"main: Entry"<<std::endl;

IClassFactory *pCf;
IUnknown *pUnk;
IMyServer *pMyServer;
HRESULT hr;

std::cout<<"main: calling CoInitialize() \n"<<std::endl;

hr=CoInitialize(NULL);
if(FAILED(hr))
{
std::cout<<"main: CoInitialize Failed!\n"<<std::endl;
exit(-1);
}

std::cout<<"main: CoInitialize OK\n"<<std::endl;
std::cout<<"main: Calling CoGetClassObject\n"<<std::endl;

hr=CoGetClassObject(CLSID_MyServer,CLSCTX_INPROC_SERVER,NULL,IID_IClassFactory,(void**)&pCf);
if(FAILED(hr)) { std::cout<<"main: CoGetClassObject
Failed!\n"<<std::endl; goto EXIT00; } std::cout<<"main:
CoGetClassObject OK\n"<<std::endl; std::cout<<"main:
callingpCf->CreateInstance(NULL,IID_IUnknown,...)"<<std::endl;
hr=pCf->CreateInstance(NULL,IID_IUnknown,(void**) &pUnk);
if(FAILED(hr)) { std::cout<<"main:
pCf->CreateInstance(NULL,IID_IUnknown,...)Failed!\n"<<std::endl; goto
CLEANUP00; } std::cout<<"main:
pCf->CreateInstance(NULL,IID_IUnknown,...)OK"<<std::endl;
std::cout<<"main:
callingpUnk->QueryInterface(IID_IMyServer,...)"<<std::endl;
hr=pUnk->QueryInterface(IID_IMyServer,(void**) &pMyServer);
if(FAILED(hr)) { std::cout<<"main:
pUnk->QueryInterface(IID_IMyServer,...)Failed!\n"<<std::endl; goto
CLEANUP01; } std::cout<<"main:
pUnk->QueryInterface(IID_IMyServer,...)OK\n"<<std::endl;
std::cout<<"main: Now Calling into the
IMyServerInterface\n"<<std::endl;
hr=pMyServer->Visible(VARIANT_TRUE); if(FAILED(hr)) { std::cout<<"main:
pMyServer->Visible() Failed!\n"<<std::endl; goto
CLEANUP02; } hr=pMyServer->Animate(VARIANT_TRUE,200); if(FAILED(hr))
{ std::cout<<"main: pMyServer->Visible() Failed!\n"<<std::endl; goto
CLEANUP02; } std::cout<<"main: pMyServer->Visible()
OK!\n"<<std::endl; Sleep(100000);CLEANUP02: std::cout<<"main: calling
IMyServer::Release"<<std::endl; pMyServer->Release();CLEANUP01:
std::cout<<"main: calling IUnknown::Release"<<std::endl;
pUnk->Release();CLEANUP00: std::cout<<"main: calling
IClassFactory::Release"<<std::endl; pCf->Release();EXIT00:
CoUninitialize(); std::cout<<"main: We are done!"<<std::endl; return
0;}//*********************************************************************The
icon appears on the system tray and the message popup works
withmouseover, but the animation does not work.With regards to
launching this COM server from a console app, is this a sideeffect? I
would think the animation would work regardless of whether Icalled
the COM server from a windowed app or a console app.Thanks,Albert




.



Relevant Pages

  • Re: "RUN AS" administartor
    ... they don't need to launch apps as an administrator. ... Microsoft MVP - Terminal Server ... > One solution is to have the user on the console run a TS session within a TS ... >> run the app under a different account. ...
    (microsoft.public.win2000.termserv.apps)
  • Re: "RUN AS" administartor
    ... log on to the console and use the machine as a workstation. ... If you want them to run an application on the server then it ... Certain apps require to be run as administrator. ... Is there any way to make the app always run with admin ...
    (microsoft.public.win2000.termserv.apps)
  • EXE running without the session
    ... I have following problem with Terminal Server on Windows 2003 Server ... There are four users that will start a console application ... (was an old DOS app compiled now as a Win32 console app) ...
    (microsoft.public.windows.terminal_services)
  • Re: WinForm App to Telnet Application
    ... The windows app ... > interact with telnet connections. ... >> telnet server. ... If you want a Dos Edit kind of console gui, ...
    (microsoft.public.dotnet.framework)
  • RE: System.Diagnostics.ProcessStartInfo
    ... The thing that made me curious is that the app I'm launching is a console ... That's a console app. ... CreateNoWindow option and spawns a separate window. ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework)