Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 22nd, 2004, 10:17 AM
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)
                _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);

  #2 (permalink)  
Old April 13th, 2004, 09:08 AM
Registered User
Join Date: Apr 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

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.

  #3 (permalink)  
Old May 30th, 2006, 05:34 AM
Registered User
Join Date: May 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

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)

Similar Threads
Thread Thread Starter Forum Replies Last Post
How To convert code aliusmankhan VB How-To 1 July 21st, 2008 12:56 PM
Help me i must convert Code vb to C# pla_2 C# 3 October 14th, 2006 12:54 AM
Convert to C# Code sanjaymannnet ASP.NET 1.0 and 1.1 Basics 1 September 16th, 2006 10:47 AM
Convert VB to C# code skdp VS.NET 2002/2003 2 March 1st, 2004 11:45 PM

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