object address

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Weimin Zhang

    #1

    object address

    I have a problem to pass an address of a control to a
    function under C# .net 2003. The control is loaded on a
    windows form, but the control is an OCX (COM component).
    The function is in a C++ static dll (like an API
    function),and the function expects a long (32 bit)
    variable for an address. I could call it from VB 6 by
    passing the control address using the VB's function
    ObjPtr and it works fine. But in C#, you can't pass the
    object name (reference) as its address,nor you
    couldgetthe addressof it. Can anybody help me to find a
    solution on it? Thanks.
  • Mattias Sjögren

    #2
    Re: object address


    Try this

    IntPtr pUnk = Marshal.GetIUnk nownForObject( YourControl.Get Ocx() );
    // call external function here and pass in pUnk
    Marshal.Release ( pUnk );



    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org

    Please reply only to the newsgroup.

    Comment

    • Weimin Zhang

      #3
      Re: object address

      Thanks Mattias!

      It works fine. Thanks again.[color=blue]
      >-----Original Message-----
      >
      >Try this
      >
      >IntPtr pUnk = Marshal.GetIUnk nownForObject( [/color]
      YourControl.Get Ocx() );[color=blue]
      >// call external function here and pass in pUnk
      >Marshal.Releas e( pUnk );
      >
      >
      >
      >Mattias
      >
      >--
      >Mattias Sjögren [MVP] mattias @ mvps.org
      >http://www.msjogren.net/dotnet/
      >Please reply only to the newsgroup.
      >.
      >[/color]

      Comment

      Working...