1.普通应用程序收发消息我一定没问题,多种方式都会用,可是Service好像完全不吃这一套,找一个应用程序句柄的FindWindow返回值都是0,发不出去也收不到.
2.如果Service根本就不能通过消息通讯,又为什么能收到我用SetTimer(server.handle....定义的WM_Timer消息?
3.另外大家有什么和Service通讯的办法?请给的详细些?
4.还有我不太会用WM_COPYDATA,请给个例子

解决方案 »

  1.   

    第四个问题我曾经问过,Look:
    http://www.csdn.net/Expert/TopicView1.asp?id=725675
      

  2.   

    Service和用户桌面是不同的桌面,不能通过SendMessage进行通信。
    可以采用Event机制和共享内存进行,----比较麻烦,要自己好好设计。
    SetTimer()在Service程序中当然没问题,在同一进程中用sendmessage也
    没问题。在同一桌面上也没问题,在不同桌面就不行。
    还有一种方法就是在用户桌面强行访问Service桌面---通过OpenDeskTop等函数。我也没用过,自己调查一下吧。
      

  3.   

    还要注意权限问题。以前做ISAPI时,最初就不能和应用程序通信(当时是共享内存文件),后来把安全性放开了,才成功了,
      

  4.   

    Platform SDK: Interprocess Communications 
    Interprocess Communications
    Microsoft® Windows® provides mechanisms for facilitating communications and data sharing between applications. Collectively, the activities enabled by these mechanisms are called interprocess communications (IPC). Some forms of IPC facilitate the division of labor among several specialized processes. Other forms of IPC facilitate the division of labor among computers on a network. 
    The following IPC mechanisms are supported by Windows: Clipboard 
    COM 
    Data Copy 
    DDE 
    File Mapping 
    Mailslots 
    Pipes 
    RPC 
    Windows Sockets
      

  5.   

    Platform SDK: Interprocess Communications The following IPC mechanisms are supported by Windows: Clipboard 
    COM 
    Data Copy 
    DDE 
    File Mapping 
    Mailslots 
    Pipes 
    RPC 
    Windows Sockets 
      

  6.   


    Platform SDK: Interprocess Communications 
    The following IPC mechanisms are supported by Windows: Clipboard 
    COM 
    Data Copy 
    DDE 
    File Mapping 
    Mailslots 
    Pipes 
    RPC 
    Windows Sockets Mailslots and Pipes are suggested for your problem
      

  7.   

    jiangsheng(蒋晟.Net) :请给些实际的例子,概念上的东西我也懂,就是实现起来...
      

  8.   

    Garden Hoses at Work
    Ruediger R. Asche
    Microsoft Developer Network Technology GroupCreated: July 29, 1994
    Revised: June 1, 1995 (redesigned class definitions; incorporated information on MFC sockets)Click to open or copy files in the CommChat sample application for this technical article.Abstract
    This article shows how named pipes can be embedded into a C++ class and discusses named pipes as a network communication mechanism. Use the accompanying sample application, CommChat, and the related article, "Communication with Class" to study possible uses of this C++ class. The CNamedPipe class hierarchy is also used to demonstrate security in the article series that begins with "Windows NT Security in Theory and Practice" and its accompanying sample suite.
    IoComplt: Win32 Winsock and Mailslot APIs
    Click to open or copy the files for the IoComplt sample.This sample illustrates the Win32® Winsock and Mailslot APIs to do a generic broadcast over IPX, UDP and Mailslot protocols.The Sockets sample contains a simple Windows NT server that uses Windows sockets. It demonstrates overlapped I/O using I/O completion ports to receive ReadFile completion notification. An I/O completion port is the most efficient form of overlapped I/O. I/O completion ports were introduced in Windows NT 3.5.CreateIoCompletionPort, as used in the server half of this sample, is only supported on Windows NT.
      

  9.   

    可以PostThreadMessage,因为你的Service实际上有一个线程。
    因为是服务,所以在你的另外的程序里,你也可以用OpenService来打开服务,并和其通信。
    第三种办法是,你可以在你的服务中定义和实现另外一个COM接口,其他的程序来访问这个接口。再有就是,因为服务里有消息循环,只要线程有消息循环就可以收到WM_TIMER消息,WM_TIMER消息可以不依赖窗口,你可以这样用:VOID CALLBACK theTimerProc(
      HWND hwnd,         // handle to window
      UINT uMsg,         // WM_TIMER message
      UINT_PTR idEvent,  // timer identifier
      DWORD dwTime       // current system time
    )
    {
        //这里处理WM_TIMER消息
    }SetTimer( NULL, 1, 1000, theTimerProc );
    再度声明,SetTimer必须放在有消息循环的线程中,普通的工作线程没有消息循环,但你也可以为其加入消息循环。
    签名:jmcooler
      

  10.   

    你这属于进程间通信问题,方法其实很多。FileMapping,Socket,COM/DCOM
    都可以。不一定非要用发送消息的方式,因为消息基本上是依赖Window的。
      

  11.   

    LRESULT SendMessage(
      HWND hWnd,      // handle to destination window
      UINT Msg,       // message
      WPARAM wParam,  // first message parameter
      LPARAM lParam   // second message parameter
    );这是SDK中SendMessge的函数原型,服务中根本就不存在窗体的概念,这是问题所在。SetTimer函数的行为正常是因为WM_TIMER消息不绝对依赖窗口。解决方法很多,上面各位提的建议可以参考。但使用socket来进行信息传递时,一定要注意:不能使用WSAAsyncSelect()处理Socket事件(可以自制Socket事件处理线程函数)。