p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# (http://p2p.wrox.com/forumdisplay.php?f=22)
-   -   Convert C++ Code to C# (http://p2p.wrox.com/showthread.php?t=10843)

skin March 22nd, 2004 10:17 AM

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)
                _value = Value;
                throw new ArgumentException();
        public static implicit operator char(WMTInt8 Value)
            return Value._value;
        public static implicit operator WMTInt8(char Value)
            return new WMTInt8(Value);


langway April 13th, 2004 09:08 AM

i don't think you should convert char in c++ to char type in c#, you should change char type to byte type,see:

www.dur.ac.uk/barry.cornelius/Java/ from.cpp.to.csharp/master.pdf

you will find an answer.


i guess you are working with a workflow project, i also have interest in it,hope to communicate with you and change our experience!

my email:
and msn messager always online.

gmoudry May 30th, 2006 05:34 AM

langway suggested to map WMTInt8 to a byte,
however, I would advise against it.
Consider this code:
  typedef char WMTInt8;
  WMTInt8 myChar = 'a';

If you translate this as
  byte myChar = 'a';
It will not compile until you insert cast statements.
(error CS0029: Cannot implicitly convert type 'char' to 'byte').
IMHO, It's better to bite the bullet, forget about type safety of 'struct WMTInt8' and translate a WMIInt8 as a C# 'char'.

http://code2code.net : C++ to C# conversion (and translation to VB.NET)

All times are GMT -4. The time now is 08:15 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.