View Single Post
  #1 (permalink)  
Old March 22nd, 2004, 10:17 AM
skin skin is offline
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Convert C++ Code to C#

Does anyone know how to convert the following C++ code into C#. I've tried myself using structs. I don't want to use unsafe code so I don't know how to implement the pointers in C#.

typedef char WMTInt8;
typedef short WMTInt16;
typedef long WMTInt32;
typedef unsigned char WMTUInt8;
typedef unsigned short WMTUInt16;
typedef unsigned long WMTUInt32;
typedef WMTInt8 WMTText;
typedef WMTText *WMTPText;
typedef WMTUInt8 *WMTPointer;
#define WMNULL ((WMTPointer)0)
#define WMFalse 0
#define WMTrue (!WMFalse)

Here is an example of how I implemented the type definition for WMTInt8, but it seems very long winded compared to a single line of code in C++ as above. Any help would be really appreciated.

using System;

namespace Wfmc.Interface2.Types.BasicTypes
{
    public struct WMTInt8
    {
        private char _value;

        public WMTInt8(char Value)
        {
            try
            {
                _value = Value;
            }
            catch
            {
                throw new ArgumentException();
            }
        }
        public static implicit operator char(WMTInt8 Value)
        {
            return Value._value;
        }
        public static implicit operator WMTInt8(char Value)
        {
            return new WMTInt8(Value);
        }
    }
}

Skin
__________________
Skin
Reply With Quote