Solved

simple C++ to Delphi

Posted on 1998-11-30
10
866 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

23 Experts available now in Live!

Get 1:1 Help Now