Ross Levis wrote:
> I've adding a plugin DLL interface to my Delphi app so 3rd party DLL's can
> utilize functions in my app. I'm not going to change pascal strings into
> pChars just to suit C++ developers so I need to write the documentation
> describing a record structure containing strings for a C++ developer.
Maybe not just for C++, but how about for *all* developers who aren't
using your version of Win32 Delphi? You're intentionally snubbing a very,
very large population of programmers.
> I know very little about the C language. Can someone confirm if I have
> this right please.
>
> MyRecord = packed record
> Artist: String;
> Title: String;
> Duration: Integer;
> Year: Word;
> Gender: ShortInt;
> BPM: Byte;
> Cuedb: SmallInt;
> Cue: LongWord;
> end;
>
> typedef struct {
> int StringLen;
> char String;
> } delphistring;
>
> typedef struct{
> delphistring *Artist;
> delphistring *Title;
Nope. Delphi's AnsiString value actually points to the char field of the
struct, not the length field. You also left out the reference-count field,
which precedes the length field. It's also difficult to capture the notion
that there's really an array of char, not just one, in the struct.
You should document it as this:
char const* Artist;
char const* Title;
Now it's just a char pointer, but it's one whose contents won't be
modified. You don't want the value to be modified because otherwise you
have to worry about reference counting.
> int Duration;
> unsigned short Year;
> signed char Gender;
> unsigned char Byte;
> short Cuedb;
> unsigned long Cue;
> } MyRecord;
You're probably better off using the types defined by the Windows API,
rather than the native C integer types. The language's types are liable to
change their sizes, just like the generic Delphi integer types. The
compiler vendors, on the other hand, will provide versions of the Windows
API headers that correspond to the compiler's integer sizes.
--
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi