您的位置:程序门 -> vb -> 基础类



求高人指点程序间通讯


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


求高人指点程序间通讯[已结贴,结贴人:wqsea]
发表于:2007-01-02 11:12:21 楼主
有两个程序a,b,一个activex   dll文件中c定义report方法,a,b同时引用,a为主动方,b为被动方,现在想a通过c   report一条消息给b,b在收到后开始处理此消息,现在问题是b无法触发c的report方法,请高人帮忙指点一下,谢谢!
c。
public   function   onreport(rptstr   as   string)   as   string
end   function

a.
set   sendcls   =   new   itfclass
sendcls.report   “hello”

b.
private     function   itfclass_onreport(rptstr   as   string)   as   string    
msgbox   rptstr
end   function
发表于:2007-01-02 12:38:141楼 得分:0
简单说就是:
a发生变化时要通知b知道,通过双方共同引用的dll实现,谢谢!
发表于:2007-01-02 20:06:212楼 得分:0
看到有人说要用activex   exe实现,一定得是这样做吗??
发表于:2007-01-02 20:17:513楼 得分:5
帮你顶,我来学习
发表于:2007-01-03 12:07:454楼 得分:40
'利用wm_copydata   发消息

'程序1
private   const   wm_copydata   =   &h4a
private   declare   function   sendmessage   lib   "user32 "   alias   "sendmessagea "   (byval   hwnd   as   long,   byval   wmsg   as   long,   byval   wparam   as   long,   lparam   as   any)   as   long
private   declare   function   findwindow   lib   "user32 "   alias   "findwindowa "   (byval   lpclassname   as   string,   byval   lpwindowname   as   string)   as   long

private   type   copydatastruct
                dwdata   as   long
                cbdata   as   long
                lpdata   as   long
end   type

private   sub   command1_click()
    dim   cd   as   copydatastruct
    dim   temp   as   string
    dim   data()   as   byte
    dim   m   as   long
   
        m   =   findwindow( "thunderrt6formdc ",   "copydata   test   form! ")
   
        temp   =   "this   is   a   test   message! "
        data   =   temp
        cd.cbdata   =   ubound(data)   +   1
        cd.lpdata   =   varptr(data(0))
        cd.dwdata   =   0
   
        sendmessage   m,   wm_copydata,   0,   cd
end   sub


'程序2
'窗体
private   declare   function   systemparametersinfo   lib   "user32 "   alias   "systemparametersinfoa "   (byval   uaction   as   long,   byval   uparam   as   long,   byref   lpvparam   as   any,   byval   fuwinini   as   long)   as   long
private   declare   function   setwindowpos   lib   "user32 "   (byval   hwnd   as   long,   byval   hwndinsertafter   as   long,   byval   x   as   long,   byval   y   as   long,   byval   cx   as   long,   byval   cy   as   long,   byval   wflags   as   long)   as   long

private   const   spi_getworkarea                 as   long   =   48
       
private   type   rect
                left   as   long
                top   as   long
                right   as   long
                bottom   as   long
end   type

private   sub   form_load()
    dim   ret   as   long
    prevwndproc   =   getwindowlong(me.hwnd,   gwl_wndproc)
    ret   =   setwindowlong(me.hwnd,   gwl_wndproc,   addressof   windproc)
    me.caption   =   "copydata   test   form! "
    me.autoredraw   =   true
end   sub

private   sub   form_unload(cancel   as   integer)
    dim   ret   as   long
    ret   =   setwindowlong(me.hwnd,   gwl_wndproc,   prevwndproc)
end   sub


'模块
public   declare   function   getwindowlong   lib   "user32 "   alias   "getwindowlonga "   (byval   hwnd   as   long,   byval   nindex   as   long)   as   long
public   declare   function   setwindowlong   lib   "user32 "   alias   "setwindowlonga "   (byval   hwnd   as   long,   byval   nindex   as   long,   byval   dwnewlong   as   long)   as   long
public   declare   function   callwindowproc   lib   "user32 "   alias   "callwindowproca "   (byval   lpprevwndfunc   as   long,   byval   hwnd   as   long,   byval   msg   as   long,   byval   wparam   as   long,   byval   lparam   as   long)   as   long
private   declare   sub   copymemory   lib   "kernel32 "   alias   "rtlmovememory "   (destination   as   any,   source   as   any,   byval   length   as   long)

    public   const   wm_copydata   =   &h4a
    public   const   gwl_wndproc   =   (-4)
public   prevwndproc   as   long

private   type   copydatastruct
                dwdata   as   long
                cbdata   as   long
                lpdata   as   long
end   type


function   windproc(byval   hwnd   as   long,   byval   msg   as   long,   byval   wparam   as   long,   byval   lparam   as   long)   as   long
      dim   cd   as   copydatastruct
      dim   temp   as   string
     
      select   case   msg
          case   wm_copydata
             
              copymemory   cd,   byval   lparam,   len(cd)
              temp   =   space(cd.cbdata)
              copymemory   byval   temp,   byval   cd.lpdata,   cd.cbdata
              form1.print   strconv(temp,   vbfromunicode)

      end   select
       
        windproc   =   callwindowproc(prevwndproc,   hwnd,   msg,   wparam,   lparam)
end   function
发表于:2007-01-03 14:34:555楼 得分:5
dde   也可以实现   而且比较简单   你google   一下
不过。net开始不支持dde了
发表于:2007-01-03 16:41:116楼 得分:0
谢谢各位的回答。我有看到过用dll实现的程式,但当我自己来做的时候发现事件不响应啊??
发表于:2007-01-06 20:13:097楼 得分:0
不知道通过dll怎么实现,请高手继续指点啊。
发表于:2007-01-07 20:29:358楼 得分:0
高手快来啊


快速检索

最新资讯
热门点击