Also I'm not sure why you're using a double* in Chararray. It should be a char* 
and is only used as a replacement for string. This is what I use:

        /// <summary>
        /// Chararray is a helper struct to marshal the strings into/out of 
unmanaged HDF.
        /// </summary>
        [StructLayout(LayoutKind.Sequential)]
        public unsafe struct Chararray
        {
            /// <summary>
            /// internal C-string pointer.
            /// </summary>
            [System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]
            private char* mText;

            /// <summary>
            /// Creator to Load text value
            /// </summary>
            /// <param name="text">string to load</param>
            public Chararray(string text)
            {
                // Duplicate 'Load' functionality
                IntPtr ipp = 
System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(text);
                this.mText = (char*)ipp;
            }

            /// <summary>
            /// an initializer to get and set the char* since it is unsafe
            /// </summary>
            public char* Text
            {
                get
                {
                    return mText;
                }
            }

            /// <summary>
            /// free the text entered with Load
            /// </summary>
            public void Cleanup()
            {
                if (mText != null)
                {
                    
System.Runtime.InteropServices.Marshal.FreeHGlobal((IntPtr)mText);
                    mText = null;
                }
            }

            /// <summary>
            /// Override of ToString to get a .NET string from C.
            /// </summary>
            /// <returns>a .NET string</returns>
            public override string ToString()
            {
                string s;
                //the HDF5 STRING is not a string but in fact a char *
                //since it is we need to translate the return into a pointer 
address

                IntPtr ipp = (IntPtr)this.Text;
                //This call is used to transform the pointer into the value of 
the pointer.

                //NOTE:  this only works with null-terminated strings.
                s = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ipp);

                return s;
            }
        }    // Chararray

Scott
> -----Original Message-----
> From: Hdf-forum [mailto:hdf-forum-boun...@hdfgroup.org] On Behalf Of
> Insane
> Sent: Tuesday, April 09, 2013 3:58 PM
> To: hdf-forum@hdfgroup.org
> Subject: Re: [Hdf-forum] c# read different datatypes
>
> Maybe, I am misunderstanding smth.
> I used this code
>  [StructLayout(LayoutKind.Sequential)]
>         public unsafe struct Chararray
>         {
>             private double* recordedText;
>
>             //an initializer to get and set the char* since it is
> unsafe
>             public double* RecordedText
>             {
>                 get
>                 {
>                     return recordedText;
>                 }
>                 set
>                 {
>                     recordedText = value;
>                 }
>             }
>
>             public override string ToString()
>             {
>                 string s = "";
>                 //the HDF5 STRING is not a string but in fact a char *
>                 //since it is we need to translate the return into a
> pointeraddress
>
>                 IntPtr ipp = (IntPtr)this.recordedText;
>                 //This call is used to transform the pointer into the
> valueof the pointer.
>
>                 //NOTE:  this only works with null-terminated strings.
>                 s
> =System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ipp);
>
>                 return s;
>             }
>         }
> -------------
> and  added  <CharArray>  instead of <char>
>
> now the returning value of "CharArray" (is "0x000007ce "      double*)
>
>
>
>
>
> --
> View this message in context: http://hdf-forum.184993.n3.nabble.com/c-
> read-different-datatypes-tp4026057p4026061.html
> Sent from the hdf-forum mailing list archive at Nabble.com.
>
> _______________________________________________
> Hdf-forum is for HDF software users discussion.
> Hdf-forum@hdfgroup.org
> http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

________________________________

This e-mail and any files transmitted with it may be proprietary and are 
intended solely for the use of the individual or entity to whom they are 
addressed. If you have received this e-mail in error please notify the sender. 
Please note that any views or opinions presented in this e-mail are solely 
those of the author and do not necessarily represent those of Exelis Inc. The 
recipient should check this e-mail and any attachments for the presence of 
viruses. Exelis Inc. accepts no liability for any damage caused by any virus 
transmitted by this e-mail.

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Reply via email to