'HANDLE *' Error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bhumithakker@gmail.com

    #1

    'HANDLE *' Error

    I am using a DLL function (complied in VC7), which takes a parameter
    of 'HANDLE *' datatype.
    The DLL developers recommend passing a HANDLE object using the
    following syntax:

    HANDLE obj =NULL;
    func(&obj);

    On successful execution of the code 'obj' is initialised to some
    value.

    This code works if used within VC++ MFC Application using VS2005.
    But the same doesnt work in VC++ Windows Form Application using
    VS2005.

    In a VC++ Windows Form Application using VS2005, the compiler expects
    the following syntax:

    HANDLE obj =NULL;
    func((HANDLE *)obj);

    This compiles but gives a runtime error, and fails to initialise
    'obj'.

    What am I doing wrong? And how can I use the DLL function in a VC++
    Windows Form Application using VS2005.

    Thanks,
    Bhumi

  • Sheng Jiang[MVP]

    #2
    Re: 'HANDLE *' Error

    You are passing a null address to the function, and the function expects a
    valida address to write to. You can use new to allocate memory on the native
    heap, pass it to the dll to retrieve the new handle, and copy the handle
    value to the managed heap.

    --
    Sheng Jiang
    Microsoft MVP in VC++
    <bhumithakker@g mail.comwrote in message
    news:1192433815 .813636.52680@z 24g2000prh.goog legroups.com...
    I am using a DLL function (complied in VC7), which takes a parameter
    of 'HANDLE *' datatype.
    The DLL developers recommend passing a HANDLE object using the
    following syntax:
    >
    HANDLE obj =NULL;
    func(&obj);
    >
    On successful execution of the code 'obj' is initialised to some
    value.
    >
    This code works if used within VC++ MFC Application using VS2005.
    But the same doesnt work in VC++ Windows Form Application using
    VS2005.
    >
    In a VC++ Windows Form Application using VS2005, the compiler expects
    the following syntax:
    >
    HANDLE obj =NULL;
    func((HANDLE *)obj);
    >
    This compiles but gives a runtime error, and fails to initialise
    'obj'.
    >
    What am I doing wrong? And how can I use the DLL function in a VC++
    Windows Form Application using VS2005.
    >
    Thanks,
    Bhumi
    >

    Comment

    • Bhumi

      #3
      Re: 'HANDLE *' Error

      On Oct 16, 1:00 am, "Sheng Jiang[MVP]"
      <sheng_ji...@ho tmail.com.discu sswrote:
      You are passing a null address to the function, and the function expects a
      valida address to write to. You can use new to allocate memory on the native
      heap, pass it to the dll to retrieve the new handle, and copy the handle
      value to the managed heap.
      >
      --
      Sheng Jiang
      Microsoft MVP in VC++<bhumithak. ..@gmail.comwro te in message
      >
      news:1192433815 .813636.52680@z 24g2000prh.goog legroups.com...
      >
      >
      >
      I am using a DLL function (complied in VC7), which takes a parameter
      of 'HANDLE *' datatype.
      The DLL developers recommend passing a HANDLE object using the
      following syntax:
      >
      HANDLE obj =NULL;
      func(&obj);
      >
      On successful execution of the code 'obj' is initialised to some
      value.
      >
      This code works if used within VC++ MFC Application using VS2005.
      But the same doesnt work in VC++ Windows Form Application using
      VS2005.
      >
      In a VC++ Windows Form Application using VS2005, the compiler expects
      the following syntax:
      >
      HANDLE obj =NULL;
      func((HANDLE *)obj);
      >
      This compiles but gives a runtime error, and fails to initialise
      'obj'.
      >
      What am I doing wrong? And how can I use the DLL function in a VC++
      Windows Form Application using VS2005.
      >
      Thanks,
      Bhumi- Hide quoted text -
      >
      - Show quoted text -
      Thanks Sheng. Got it to work now.

      Thanks,
      Bhumi

      Comment

      • Ben Voigt [C++ MVP]

        #4
        Re: 'HANDLE *' Error


        <bhumithakker@g mail.comwrote in message
        news:1192433815 .813636.52680@z 24g2000prh.goog legroups.com...
        >I am using a DLL function (complied in VC7), which takes a parameter
        of 'HANDLE *' datatype.
        The DLL developers recommend passing a HANDLE object using the
        following syntax:
        >
        HANDLE obj =NULL;
        func(&obj);
        >
        On successful execution of the code 'obj' is initialised to some
        value.
        >
        This code works if used within VC++ MFC Application using VS2005.
        But the same doesnt work in VC++ Windows Form Application using
        VS2005.
        It should, because that is the correct version.

        >
        In a VC++ Windows Form Application using VS2005, the compiler expects
        the following syntax:
        >
        HANDLE obj =NULL;
        func((HANDLE *)obj);
        >
        This compiles but gives a runtime error, and fails to initialise
        'obj'.
        >
        What am I doing wrong? And how can I use the DLL function in a VC++
        Windows Form Application using VS2005.
        >
        Thanks,
        Bhumi
        >

        Comment

        Working...