Solved

simple C++ to Delphi

Posted on 1998-11-30
10
868 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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