Solved

simple C++ to Delphi

Posted on 1998-11-30
10
876 Views
Last Modified: 2008-02-26
Hi,

At least I think this are simple translations, I only don't know enough of C++ to be sure. Can you help me translate the following? Thanks:

/* XLATOFF */
#ifdef  IS_32
#define DBTFAR
#else
#define DBTFAR  far
#endif
/* XLATON */

#ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
#define _WCHAR_T_DEFINED
#endif

#ifndef GUID_DEFINED
    #define GUID_DEFINED
    typedef struct _GUID {
        ULONG   Data1;
        unsigned short Data2;
        unsigned short Data3;
        unsigned char Data4[8];
    } GUID;
#endif // !defined(GUID_DEFINED)

what is winversion 0x040A in Delphi? (does it exist?=WIN32?)

#if(WINVER >= 0x040A)
blablabla
#endif /* WINVER >= 0x040A */

What is UNICODE in Delphi?

#ifdef UNICODE
typedef DEV_BROADCAST_PORT_W     DEV_BROADCAST_PORT;
typedef PDEV_BROADCAST_PORT_W    PDEV_BROADCAST_PORT;
#else
typedef DEV_BROADCAST_PORT_A     DEV_BROADCAST_PORT;
typedef PDEV_BROADCAST_PORT_A    PDEV_BROADCAST_PORT;
#endif

0
Comment
Question by:ZifNab
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 3

Expert Comment

by:philipleighs
ID: 1348661
You may not need to translate this:
WideChar is already defined in Delphi 3, 4
Also, there is a GUID structure (and associated routines) in Delphi called TGuid.

0
 
LVL 4

Expert Comment

by:erajoj
ID: 1348662
This is a joke, right?
(If it isn't, I apologize)

/// John
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1348663
At first I thought "why would this be a joke?" That is until I saw who posted it...
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 3

Expert Comment

by:philipleighs
ID: 1348664
... not that zif is funny looking or anything. I mean that you (zif) are *the* EE expert.
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1348665
My point exactly!
0
 
LVL 8

Author Comment

by:ZifNab
ID: 1348666
hehe, gringrin, groble, groble, gniffel,gniffel.cof,cof. Had a nice day? :-P? Nice to hear from you all again.
0
 
LVL 10

Accepted Solution

by:
Lischke earned 50 total points
ID: 1348667
Hi ZifNab,

here my comments:

-----------------------------------------------------------
/* XLATOFF */
#ifdef  IS_32
#define DBTFAR
#else
#define DBTFAR  far
#endif
/* XLATON */

I don't know what IS_32 stands for, but you have to decide wether you want to have it to be defined (that's just an assumption, you don't really have it defined). Depending on it either DBFAR is omitted (a macro without text) or DBFAR stands for the term far (e.g. as calling covention in a function declaration).

-----------------------------------------------------------
#ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
#define _WCHAR_T_DEFINED
#endif

This is not needed in Delphi. Just declare each occurence of wchar_t as WideChar.

-----------------------------------------------------------
#ifndef GUID_DEFINED
    #define GUID_DEFINED
    typedef struct _GUID {
        ULONG   Data1;
        unsigned short Data2;
        unsigned short Data3;
        unsigned char Data4[8];
    } GUID;
#endif // !defined(GUID_DEFINED)

This is already defined in Delphi.

-----------------------------------------------------------
what is winversion 0x040A in Delphi? (does it exist?=WIN32?)

#if(WINVER >= 0x040A)
blablabla
#endif /* WINVER >= 0x040A */

Unfortunately, you don't have the choice to compile your program depending on the current Windows version. You either assume to have a version of 4.0+ or not (and you have to compile your program accordingly). If the declarations contained in the conditional definiton are available on your target system, then include them into your program, else not...

-----------------------------------------------------------
What is UNICODE in Delphi?

Well, UNICODE in Delphi is the same as UNICODE in C (and Windows), fortunately :-) Unicode means that all characters in a program use two bytes of storage rather then one. So you can store up to 65535 different characters in a WideChar (the Delphi equivalent to a unicode character). That's enough to handle almost each language written today on earth, plus lots of additional signs (say money symbols etc.)

-----------------------------------------------------------
#ifdef UNICODE
typedef DEV_BROADCAST_PORT_W     DEV_BROADCAST_PORT;
typedef PDEV_BROADCAST_PORT_W    PDEV_BROADCAST_PORT;
#else
typedef DEV_BROADCAST_PORT_A     DEV_BROADCAST_PORT;
typedef PDEV_BROADCAST_PORT_A    PDEV_BROADCAST_PORT;
#endif

Delphi's VCL is compiled to have all function and structures without a W suffix to be for ANSI only. But very often there's a unicode version available (simply try adding a W to the function and see if it compiles). A typical example is SendMessage which is defined as using ANSI, and additionally as SendMessageA (this is actually the same as SendMessage, it is bound to the same function in Windows.pas) and SendMessageW for unicode.

Following this predrawn way you'd define your stuff as would unicode be declared, BUT also as wouldn't it. I don't recommend to declare an own symbol (say UNICODE) to mirror the C syntax one-to-one. Just do it as Inprise did!

Assuming these identifiers are already defined:

DEV_BROADCAST_PORT_W
PDEV_BROADCAST_PORT_W
DEV_BROADCAST_PORT_A
PDEV_BROADCAST_PORT_A

your only addition would be:

type
  DEV_BROADCAST_PORT = DEV_BROADCAST_PORT_A;
  PDEV_BROADCAST_PORT = PDEV_BROADCAST_PORT_A;

Inc cases where you need unicode you would use DEV_BROADCAST_PORT_W instead of DEV_BROADCAST_PORT etc.

Ciao, Mike
0
 
LVL 8

Author Comment

by:ZifNab
ID: 1348668
Liscke, thanks for the info, but I already knew this... but because of the work you've put in answering this q'n, you'll get the points.

But, now, let's just use this thread for talking about,.... you name it...

Zif.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1348669
Well, I'm wondering why you then asked the question? Is it just to make a thread up and running? Anyway, I don't mind answering even "dummy" questions :-) as long as it takes not too long and is promising a bit fun...

Read you again,

Ciao, Mike
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1348670
Hi, Zif, do you mean "translate" or "explain"? By "translate", one shoould mean getting those C++ code into Delphi code, right?

^_^
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question