none
Problem in Interop RRS feed

  • Question

  • Hi,

    I have a problem in interop.

    I have a c++ dll that has a function that takes the control handle as input and does some manipulation on the editable field.

    // HINSTANCE SetInstanceHandle(HINSTANCE hInstance)

    I have a .NET form in which I have a textbox control. Now I import the c++ dll and invoke the function. Now, I pass the textbox control's handle as Control.ControlAccessibleObject .Handle (which returns a IntPtr). This gives me an error quoting "The runtime has encountered a fatal error. The address of the error was at 0x79ef04d2, on thread 0x364. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack."

    I dont know what this error imply. I am also afraid that my way of accessing the handle in .NET is wrong.

    Please guide me to access this c++ function.

    Thanks,

    Mani

     

     

     

     

    Thursday, October 12, 2006 2:39 PM

Answers

  • If you want to get the HINSTANCE from a code module, use System.Runtime.InteropServices.Marshal.GetHINSTANCE()

     

    Friday, October 13, 2006 7:22 AM
    Moderator

All replies

  • A HINSTANCE is not the same as a HWND (which is what Control.Handle returns). What makes you think the function takes a control handle?

     

    Thursday, October 12, 2006 2:58 PM
    Moderator
  • oh am sorry :(

    am a novice in VC++ and MFC.

    So whats the equivalent of HINSTANCE in .NET ?

    Thanks,

    mani

    Thursday, October 12, 2006 3:29 PM
  • If you want to get the HINSTANCE from a code module, use System.Runtime.InteropServices.Marshal.GetHINSTANCE()

     

    Friday, October 13, 2006 7:22 AM
    Moderator