Solved

simple C++ to Delphi

Posted on 1998-11-30
10
884 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

691 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