locked
asp.net findwindow 总是找不到窗口用getlasterror()=1008 RRS feed

  • 问题

  • 我用findwindow主要是找到一个在服务器上运行的窗口然后给窗口发送消息完成相应操作。

    我用findwindow(null,"窗口标题")总是返回为0,用Marshal.GetLastWin32Error()捕获错误显示为1008,,意思“试图引用不存在的令牌”。我在服务器上用winform程序调用findwindow就成功,无法理解。

    要命的是,在本地调试ASP.NET的时候findwindow成功,放到服务器上是才出现上述这个现象。

    我这个是在一个web服务里面使用的,不过用的是国产的PHPRPC这个轻量级的WEB服务,主要方便在手机里调用。

    看到CSDN上有人说在可以调用的,他给出的源码是web服务的,可惜手机无法使用web服务,所以我也没测他的代码。

    望有高手解决,谢谢。

     

    2010年3月26日 15:48

答案

  • 服务默认是不和桌面交互的,找不到桌面上的窗口很正常。重写你的桌面程序,使得你的服务可以使用其他方式控制,比如socket、remoting、WCF、命名管道等等

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    • 已建议为答案 Weng Yuli 2010年3月27日 13:38
    • 已标记为答案 KeFang Chen 2010年4月1日 4:08
    2010年3月26日 17:09
    版主
  • VS调试的时候默认使用的是在用户桌面上运行的Cassini Web 服务器,不是IIS,

    通讯方法前面不是说了?



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    • 已标记为答案 edzjx 2010年7月15日 10:11
    2010年3月28日 13:31
    版主
  • 不是,你可以在winform程序里做一个socket或者WCF服务器然后用网页控制。

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    • 已标记为答案 edzjx 2010年7月15日 10:11
    2010年4月7日 11:52
    版主

全部回复

  • 服务默认是不和桌面交互的,找不到桌面上的窗口很正常。重写你的桌面程序,使得你的服务可以使用其他方式控制,比如socket、remoting、WCF、命名管道等等

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    • 已建议为答案 Weng Yuli 2010年3月27日 13:38
    • 已标记为答案 KeFang Chen 2010年4月1日 4:08
    2010年3月26日 17:09
    版主
  • 我做过.net windows服务 确实如你所说如果是window服务不跟桌面交互,服务在桌面未登录的时候就运行了,这个时候可也通过其他途径解决windows服务与桌面交互的问题。

    我这个是web程序。我无法理解,我什么在VS中调试模式下可以运行。而放到IIS上就不可以了,感觉不是权限,我把Internet来宾账户跟ASP.NET账户放到administrators组里也没用。

    MSDN的文档,我没找到相关说明,google了好多英文论坛也没找出具体原因只是说的很模糊。

    2010年3月28日 7:07
  • 另外,我想知道ASP.NET 这种网页形式跟winform窗口程序交互好办法,因为有些功能必须在服务器的winform下在能实现,而且我调用这个winform会立刻返回一个值给ASP.NET。这样如何操作?
    2010年3月28日 7:20
  • VS调试的时候默认使用的是在用户桌面上运行的Cassini Web 服务器,不是IIS,

    通讯方法前面不是说了?



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    • 已标记为答案 edzjx 2010年7月15日 10:11
    2010年3月28日 13:31
    版主
  • 你的说的socket、remoting、WCF、命名管道这些都能实现,网页调用form相应的功能?我记得socket就是网络通信,我的winform程序需要做个后台线程读取socket数据,然后再发给网页,网页在全局事件里面我还要生成一个线程专门负责读取winform发来的数据。要命的是我的web是phprpc的web服务。我想过操作起来比较麻烦。

    remoting,好像也可以在学习中。但是感觉这东西好像是调用远程的类。我的winform是一个自动截图程序,不知道能不能搞定。

    wcf跟命名通道太新,还没怎么看过。

    2010年4月7日 1:47
  • 不是,你可以在winform程序里做一个socket或者WCF服务器然后用网页控制。

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    • 已标记为答案 edzjx 2010年7月15日 10:11
    2010年4月7日 11:52
    版主
  • 嗯,后来用同步的socket做的。效果还不错。现在一些web服务可以窗口的形式发布服务。很强大了。

    2010年7月15日 10:10