C++/CLI DateTime method argument

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

    #1

    C++/CLI DateTime method argument

    Hi everybody.

    I'm writing a .NET wrapper class for a native C++ library and decided
    to do it in C++/CLI. One of the problems I ran in to is the following.

    In C++ I have the following

    public ref class MyClass
    {
    ....
    bool DoIt(DateTime^% date);
    bool DoIt2([OutAttribute] DateTime^% date)
    }

    which I think should translate into a method calls with c# syntax:

    bool DoIt(ref DateTime date);
    bool DoIt2(out DateTime date);

    So I was a bit puzzled when the following showed up:

    bool DoIt(ref ValueType date);

    Where is my type safety? What am I doing wrong? Am I trying to do
    something (returning value types from c++/cli via ref and out) that is
    just not possible?

    bool DoIt(ref ValueType date);

  • Ben Voigt [C++ MVP]

    #2
    Re: C++/CLI DateTime method argument


    <soren.enemaerk e@gmail.comwrot e in message
    news:1190753360 .562742.319860@ 22g2000hsm.goog legroups.com...
    Hi everybody.
    >
    I'm writing a .NET wrapper class for a native C++ library and decided
    to do it in C++/CLI. One of the problems I ran in to is the following.
    >
    In C++ I have the following
    >
    public ref class MyClass
    {
    ...
    bool DoIt(DateTime^% date);
    bool DoIt2([OutAttribute] DateTime^% date)
    }
    >
    which I think should translate into a method calls with c# syntax:
    >
    bool DoIt(ref DateTime date);
    bool DoIt2(out DateTime date);
    >
    So I was a bit puzzled when the following showed up:
    >
    bool DoIt(ref ValueType date);
    >
    Where is my type safety? What am I doing wrong? Am I trying to do
    something (returning value types from c++/cli via ref and out) that is
    just not possible?
    You're using tracking handles (^) with a value type, which is not needed or
    desired.

    Just "bool DoIt(DateTime% date);" will work properly.
    >
    bool DoIt(ref ValueType date);
    >

    Comment

    • soren.enemaerke@gmail.com

      #3
      Re: C++/CLI DateTime method argument

      On 25 Sep., 23:24, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
      <soren.enemae.. .@gmail.comwrot e in message
      >
      news:1190753360 .562742.319860@ 22g2000hsm.goog legroups.com...
      >
      >
      >
      >
      >
      Hi everybody.
      >
      I'm writing a .NET wrapper class for a native C++ library and decided
      to do it in C++/CLI. One of the problems I ran in to is the following.
      >
      In C++ I have the following
      >
      public ref class MyClass
      {
      ...
      bool DoIt(DateTime^% date);
      bool DoIt2([OutAttribute] DateTime^% date)
      }
      >
      which I think should translate into a method calls with c# syntax:
      >
      bool DoIt(ref DateTime date);
      bool DoIt2(out DateTime date);
      >
      So I was a bit puzzled when the following showed up:
      >
      bool DoIt(ref ValueType date);
      >
      Where is my type safety? What am I doing wrong? Am I trying to do
      something (returning value types from c++/cli via ref and out) that is
      just not possible?
      >
      You're using tracking handles (^) with a value type, which is not needed or
      desired.
      >
      Just "bool DoIt(DateTime% date);" will work properly.
      >
      >
      >
      >
      >
      bool DoIt(ref ValueType date);- Skjul tekst i anførselstegn -
      >
      - Vis tekst i anførselstegn -- Skjul tekst i anførselstegn -
      >
      - Vis tekst i anførselstegn -
      Thanks Ben, worked like a charm.

      Comment

      • Sheng Jiang[MVP]

        #4
        Re: C++/CLI DateTime method argument

        DateTime is a value type, however the track handle ^ makes the parameter to
        be boxed. C# does not understand the type of a boxed value type, but C++/CLI
        does. So you have ref ValueType in C#, and DateTime^ in C++/CLI.
        --
        Sheng Jiang
        Microsoft MVP in VC++
        <soren.enemaerk e@gmail.comwrot e in message
        news:1190753360 .562742.319860@ 22g2000hsm.goog legroups.com...
        Hi everybody.
        >
        I'm writing a .NET wrapper class for a native C++ library and decided
        to do it in C++/CLI. One of the problems I ran in to is the following.
        >
        In C++ I have the following
        >
        public ref class MyClass
        {
        ...
        bool DoIt(DateTime^% date);
        bool DoIt2([OutAttribute] DateTime^% date)
        }
        >
        which I think should translate into a method calls with c# syntax:
        >
        bool DoIt(ref DateTime date);
        bool DoIt2(out DateTime date);
        >
        So I was a bit puzzled when the following showed up:
        >
        bool DoIt(ref ValueType date);
        >
        Where is my type safety? What am I doing wrong? Am I trying to do
        something (returning value types from c++/cli via ref and out) that is
        just not possible?
        >
        bool DoIt(ref ValueType date);
        >

        Comment

        Working...