Can't pass hDC back to Client with DCOM 
Author Message
 Can't pass hDC back to Client with DCOM

I am working on an application that will be taking screen shots from a
server and passing them back to the client.  The DCOM server basically
needs to run GetDesktopWindow to grab the image and then pass that
reference back to the client machine.

I've tried several ways to pass the hDC back to the client without
success.  If I run the server same machine as the client, it works,
however when the two are seperated, all that is returned is the long
number that isn't handled as a DC at all.

Any one know what to do here?  Your help is GREATLY appreciated!!!



Fri, 10 Jun 2005 22:34:43 GMT  
 Can't pass hDC back to Client with DCOM

Quote:
> I am working on an application that will be taking screen shots from a
> server and passing them back to the client.  The DCOM server basically
> needs to run GetDesktopWindow to grab the image and then pass that
> reference back to the client machine.

> I've tried several ways to pass the hDC back to the client without
> success.  If I run the server same machine as the client, it works,
> however when the two are seperated, all that is returned is the long
> number that isn't handled as a DC at all.

> Any one know what to do here?  Your help is GREATLY appreciated!!!

My guess is that this is beyond the realm of DCOM's capabilities as the
handle on the server means nothing to the client.  I would assume the best
way to do this would be to save the screen shot as a file and send the file
back, or at least a path to the file if it is in a shared directory.

-d



Sat, 11 Jun 2005 04:51:16 GMT  
 Can't pass hDC back to Client with DCOM
Surely there is a way to do this without saving the file to disk.  For
what I am doing, saving a file to disk would present a huge
bottleneck.  I've found that part of my problem may be that I am using
an ActiveX EXE which obviously runs in a separate process on another
machine, and when dealing with DC's you have to remain in-Process to
achive this.  Is there any way to just pass a bitmap back to the
client process without saving to file? - Maybe in a memory DC?

--HELP!!  Thanks!!

Quote:



> > I am working on an application that will be taking screen shots from a
> > server and passing them back to the client.  The DCOM server basically
> > needs to run GetDesktopWindow to grab the image and then pass that
> > reference back to the client machine.

> > I've tried several ways to pass the hDC back to the client without
> > success.  If I run the server same machine as the client, it works,
> > however when the two are seperated, all that is returned is the long
> > number that isn't handled as a DC at all.

> > Any one know what to do here?  Your help is GREATLY appreciated!!!

> My guess is that this is beyond the realm of DCOM's capabilities as the
> handle on the server means nothing to the client.  I would assume the best
> way to do this would be to save the screen shot as a file and send the file
> back, or at least a path to the file if it is in a shared directory.

> -d



Sat, 11 Jun 2005 10:59:29 GMT  
 Can't pass hDC back to Client with DCOM
You can use OleCreatePictureIndirect from VB to take the desktop snapshot
and cast that picture to a StdPicture object. You may then be able to pass
that as an object to the server, which if successfully you should be able to
manipulate as required.  Code showing how to perform the
OleCreatePictureIndirect method is available at
http://www.mvps.org/vbnet/code/bitmap/printscreenole.htm

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.


| Surely there is a way to do this without saving the file to disk.  For
| what I am doing, saving a file to disk would present a huge
| bottleneck.  I've found that part of my problem may be that I am using
| an ActiveX EXE which obviously runs in a separate process on another
| machine, and when dealing with DC's you have to remain in-Process to
| achive this.  Is there any way to just pass a bitmap back to the
| client process without saving to file? - Maybe in a memory DC?
|
| --HELP!!  Thanks!!
|



| > > I am working on an application that will be taking screen shots from a
| > > server and passing them back to the client.  The DCOM server basically
| > > needs to run GetDesktopWindow to grab the image and then pass that
| > > reference back to the client machine.
| > >
| > > I've tried several ways to pass the hDC back to the client without
| > > success.  If I run the server same machine as the client, it works,
| > > however when the two are seperated, all that is returned is the long
| > > number that isn't handled as a DC at all.
| > >
| > > Any one know what to do here?  Your help is GREATLY appreciated!!!
| >
| > My guess is that this is beyond the realm of DCOM's capabilities as the
| > handle on the server means nothing to the client.  I would assume the
best
| > way to do this would be to save the screen shot as a file and send the
file
| > back, or at least a path to the file if it is in a shared directory.
| >
| > -d



Sat, 11 Jun 2005 11:29:45 GMT  
 Can't pass hDC back to Client with DCOM

Quote:
> Surely there is a way to do this without saving the file to disk.  For
> what I am doing, saving a file to disk would present a huge
> bottleneck.

where are you that your network is faster than your harddrive?  while
writing to the harddrive may take some time, it will take less time than
moving the same amount of data across a network. the network is the bottle
neck.

Quote:
> I've found that part of my problem may be that I am using
> an ActiveX EXE which obviously runs in a separate process on another
> machine, and when dealing with DC's you have to remain in-Process to
> achive this.  Is there any way to just pass a bitmap back to the
> client process without saving to file? - Maybe in a memory DC?

I don't know how to do it in VB, but I do know how, in other languages, to
serialize an object in order to send it over a network [1].

another solution, by the way (though it is actually a variation on the
serialize and send method) would be to write a web script (.asp perhaps)
which would take the screen shot and send the data back via http.  This
should be trivial to implement.

#[1] python example
# see http://www.python.org/doc/current/lib/module-cPickle.html
# server code
def return_bmp():
    return cPickle.dumps(bitmap_object)

# client code
b = cPickle.loads(server_obj.return_bmp)



Sat, 11 Jun 2005 16:36:57 GMT  
 Can't pass hDC back to Client with DCOM
Randy,

Thanks for the tip.  This works if I run in the same program, but when
I try to access from another app, it tells me that the method failed.
This has the speed that I am looking for, but it won't let me pass the
object over.  Any thoughts...maybe I am missing something.  Here is
what I have on the server side:

SERVER SIDE *************************

Public Property Get ImageObj() As StdPicture

    Set ImageObj = GetRemoteDesktop

End Property

Public Function GetRemoteDesktop() As Picture
    Dim Pic As PicBmp
    Dim IPic As IPicture
    Dim IID_IDispatch As GUID
    Dim hWndSrc As Long
    Dim hDCSrc As Long
    Dim hDCMemory As Long
    Dim hBmp As Long
    Dim hBmpPrev As Long
    Dim WidthSrc As Long
    Dim HeightSrc As Long

    WidthSrc = Screen.Width \ Screen.TwipsPerPixelX
    HeightSrc = Screen.Height \ Screen.TwipsPerPixelY

    hWndSrc = GetDesktopWindow()
    hDCSrc = GetWindowDC(hWndSrc)

    hDCMemory = CreateCompatibleDC(hDCSrc)

    hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
    hBmpPrev = SelectObject(hDCMemory, hBmp)

    Ret = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, 0, 0,
vbSrcCopy)

    hBmp = SelectObject(hDCMemory, hBmpPrev)

    Ret = DeleteDC(hDCMemory)
    Ret = ReleaseDC(hWndSrc, hDCSrc)

    With IID_IDispatch
        .Data1 = &H20400
        .Data4(0) = &HC0
        .Data4(7) = &H46
    End With

    With Pic
        .Size = Len(Pic)
        .Type = vbPicTypeBitmap
        .hBmp = hBmp
        .hPal = 0&
    End With

    Ret = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)

    Set GetRemoteDesktop = IPic

    GetCursorPos MousePos

End Function

CLIENT SIDE CALLING ***************************************

Sub GetWindowImg

    Dim objImg as StdPicture
    Dim objAdmin as ServerAdmin    

    Set objAdmin = New ServerAdmin

    'FAILS RIGHT HERE!!!! SAYS "METHOD _ImageObj FAILED"
    Set objImg = objAdmin.ImageObj
End Sub

************************************************

Any clue as to why this fails?

Thanks!

Quote:

> You can use OleCreatePictureIndirect from VB to take the desktop snapshot
> and cast that picture to a StdPicture object. You may then be able to pass
> that as an object to the server, which if successfully you should be able to
> manipulate as required.  Code showing how to perform the
> OleCreatePictureIndirect method is available at
> http://www.mvps.org/vbnet/code/bitmap/printscreenole.htm

> --

> Randy Birch
> MVP Visual Basic
> http://www.mvps.org/vbnet/
> Please respond only to the newsgroups so all can benefit.



> | Surely there is a way to do this without saving the file to disk.  For
> | what I am doing, saving a file to disk would present a huge
> | bottleneck.  I've found that part of my problem may be that I am using
> | an ActiveX EXE which obviously runs in a separate process on another
> | machine, and when dealing with DC's you have to remain in-Process to
> | achive this.  Is there any way to just pass a bitmap back to the
> | client process without saving to file? - Maybe in a memory DC?
> |
> | --HELP!!  Thanks!!
> |




> | > > I am working on an application that will be taking screen shots from a
> | > > server and passing them back to the client.  The DCOM server basically
> | > > needs to run GetDesktopWindow to grab the image and then pass that
> | > > reference back to the client machine.
> | > >
> | > > I've tried several ways to pass the hDC back to the client without
> | > > success.  If I run the server same machine as the client, it works,
> | > > however when the two are seperated, all that is returned is the long
> | > > number that isn't handled as a DC at all.
> | > >
> | > > Any one know what to do here?  Your help is GREATLY appreciated!!!
> | >
> | > My guess is that this is beyond the realm of DCOM's capabilities as the
> | > handle on the server means nothing to the client.  I would assume the
>  best
> | > way to do this would be to save the screen shot as a file and send the
>  file
> | > back, or at least a path to the file if it is in a shared directory.
> | >
> | > -d



Mon, 13 Jun 2005 04:26:31 GMT  
 Can't pass hDC back to Client with DCOM
Randy,

Thanks for the tip.  This works if I run in the same program, but when
I try to access from another app, it tells me that the method failed.
This has the speed that I am looking for, but it won't let me pass the
object over.  Any thoughts...maybe I am missing something.  Here is
what I have on the server side:

SERVER SIDE *************************

Public Property Get ImageObj() As StdPicture

    Set ImageObj = GetRemoteDesktop

End Property

Public Function GetRemoteDesktop() As Picture
    Dim Pic As PicBmp
    Dim IPic As IPicture
    Dim IID_IDispatch As GUID
    Dim hWndSrc As Long
    Dim hDCSrc As Long
    Dim hDCMemory As Long
    Dim hBmp As Long
    Dim hBmpPrev As Long
    Dim WidthSrc As Long
    Dim HeightSrc As Long

    WidthSrc = Screen.Width \ Screen.TwipsPerPixelX
    HeightSrc = Screen.Height \ Screen.TwipsPerPixelY

    hWndSrc = GetDesktopWindow()
    hDCSrc = GetWindowDC(hWndSrc)

    hDCMemory = CreateCompatibleDC(hDCSrc)

    hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
    hBmpPrev = SelectObject(hDCMemory, hBmp)

    Ret = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, 0, 0,
vbSrcCopy)

    hBmp = SelectObject(hDCMemory, hBmpPrev)

    Ret = DeleteDC(hDCMemory)
    Ret = ReleaseDC(hWndSrc, hDCSrc)

    With IID_IDispatch
        .Data1 = &H20400
        .Data4(0) = &HC0
        .Data4(7) = &H46
    End With

    With Pic
        .Size = Len(Pic)
        .Type = vbPicTypeBitmap
        .hBmp = hBmp
        .hPal = 0&
    End With

    Ret = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)

    Set GetRemoteDesktop = IPic

    GetCursorPos MousePos

End Function

CLIENT SIDE CALLING ***************************************

Sub GetWindowImg

    Dim objImg as StdPicture
    Dim objAdmin as ServerAdmin    

    Set objAdmin = New ServerAdmin

    'FAILS RIGHT HERE!!!! SAYS "METHOD _ImageObj FAILED"
    Set objImg = objAdmin.ImageObj
End Sub

************************************************

Any clue as to why this fails?

Thanks!

Quote:



> > Surely there is a way to do this without saving the file to disk.  For
> > what I am doing, saving a file to disk would present a huge
> > bottleneck.

> where are you that your network is faster than your harddrive?  while
> writing to the harddrive may take some time, it will take less time than
> moving the same amount of data across a network. the network is the bottle
> neck.

> > I've found that part of my problem may be that I am using
> > an ActiveX EXE which obviously runs in a separate process on another
> > machine, and when dealing with DC's you have to remain in-Process to
> > achive this.  Is there any way to just pass a bitmap back to the
> > client process without saving to file? - Maybe in a memory DC?

> I don't know how to do it in VB, but I do know how, in other languages, to
> serialize an object in order to send it over a network [1].

> another solution, by the way (though it is actually a variation on the
> serialize and send method) would be to write a web script (.asp perhaps)
> which would take the screen shot and send the data back via http.  This
> should be trivial to implement.

> #[1] Python example
> # see http://www.python.org/doc/current/lib/module-cPickle.html
> # server code
> def return_bmp():
>     return cPickle.dumps(bitmap_object)

> # client code
> b = cPickle.loads(server_obj.return_bmp)



Tue, 14 Jun 2005 12:52:36 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Get hDc for controls that don't expose hDc property

2. Passing records back to client

3. Client/Server Question - Passing Information back

4. DCOM client hangs when passing large byte arrays

5. ADO 2.0 Error passing recordset from DCOM Server to Remote Client

6. 'Canned' data in VB program

7. Dcom-Clients without Client for Microsoft-Networks

8. Passing UDT's between Control & Client

9. col.Remove and col.Add won't work back-to-back

10. Passing hDC to a DLL ...

11. Passing hDC from VB to OCX...

12. BitBlitting from Picture.hDC to Printer.hDC

 

 
Powered by phpBB® Forum Software