Solved

simple C++ to Delphi

Posted on 1998-11-30
10
861 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now