Create "ghost" form from Win32 handle

This is a discussion on Create "ghost" form from Win32 handle within the C# Programming forums, part of the General Programming Boards category; Hi, I'd like to know if there is any mean of accessing a native window win32 structure from its handle ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    58

    Create "ghost" form from Win32 handle

    Hi,
    I'd like to know if there is any mean of accessing a native window win32 structure from its handle passed to a .net assembly.
    In theory it would be possible since the handle is a system unique identifier of a structure; for methods it works using the windows message pump + PInvoke. The handle is referenced in a system ressources table with it's reserved space. Since this structure if of type "form"/"window", then the offsets to its properties would be the same whatever the active process is accessing them, both for managed and unmamaged processes. I'd even be OK with PInvoke.
    If anyone has gone thru this experience I'd be happy to learn about.
    Thanks!

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,467
    You will not want to use PInvoke in this circumstance, me thinks. PInvoke forces you to introduce all the necessary invoke declarations. A form handler becomes a rather complex structure once you plan to start interacting with it from within managed code. Furthermore PInvoke stands for Platform Invoke, and the word "platform" there is a strong giveaway to the weaknesses of this method once it becomes too complex in your managed code. Too many declarations, hard to port across different API versions,...

    So instead of the PInvoke mechanism, I'd advise you use the C++ Interop facilities by wrapping the needed APIs around a thin C++ layer. There's stuff about it on MSDN.

    edit: btw, what's a "ghost" form?
    Last edited by Mario F.; 02-21-2010 at 08:44 PM.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Quote Originally Posted by Mario F. View Post
    edit: btw, what's a "ghost" form?
    I think he's asking about how to take a native window and wrap it in a .NET form object. That sort of thing used to work in MFC (you could wrap an MFC control around a window without giving the MFC object "ownership") but in .NET that won't work AFAIK.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. no errors but still errors
    By Megatron in forum Windows Programming
    Replies: 7
    Last Post: 01-12-2003, 10:21 PM
  2. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  3. Create a Window in a Win32 Dll?
    By RedLenses in forum C++ Programming
    Replies: 1
    Last Post: 05-21-2002, 02:21 PM
  4. create form in vc++6
    By johnd in forum Windows Programming
    Replies: 1
    Last Post: 12-12-2001, 03:54 AM
  5. Create a Form Like Window in C
    By jayash in forum C Programming
    Replies: 2
    Last Post: 08-28-2001, 01:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21