Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #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);

Reply With Quote
  #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.

Reply With Quote
  #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)

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 06:50 PM.

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