Skip to main content
gamedev.net
🔒 Locked

Class's Binary Representation

Started by Eli Gottlieb Jun 18, 2002 at 1:10 PM 5 replies 450+ views
Original Post
Eli Gottlieb
Eli Gottlieb
Will a class made in Delphi be accessible from C++ on Windows? void Signature(void* Pointer) { PObject(Pointer)->ShowMessage("Why do we need so many pointers?"); };
void Signature(void* Pointer){PObject(Pointer)->ShowMessage("Why do we need so many pointers?");};
LessBread
LessBread
I think so - I know that structures and functions written in Pascal and built with Delphi can be accessed in C on Windows. Last year I wrote a plugin in C for an app written in Delphi. It took a bit of fussing to get the datatypes correct but I succeeded. Take a look at the sample plugins for PE Explorer - compare the Pascal source with the C source to get a sense of the differences and similarities between the two languages.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Fruny
Fruny
No.

For example, C strings are NULL-terminated, while Pascal strings hold the length of the string in their first byte. Therefore, you cannot pass a C string to a Pascal function, and conversely.

You have to use a framework like COM or CORBA that do the translation for you.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Eli Gottlieb
Eli Gottlieb
Thank you LessBread. Fruny, you have no idea what the question was. 1.Pascal CAN declare, manage and use null-terminated strings. 2.Delphi allows one to convert between the two with a simple typecast. 3.I had thought that the INTERFACE types were to declare abstract classes that don't derive from TObject in order to work outside of Delphi. They're actually to associate a GUID with an abstract class not derived from TObject. 4.What LessBread says agrees with my observation that calling a TObject derived class in C++ Builder as a non-TObject-derived one works. 5.When you pass an object to a function you NEVER pass the actual object, only a pointer to it.

void Signature(void* Pointer)
{
PObject(Pointer)->ShowMessage("Why do we need so many pointers?");
};


[edited by - Eli Gottlieb on June 18, 2002 7:34:49 PM]
void Signature(void* Pointer){PObject(Pointer)->ShowMessage("Why do we need so many pointers?");};
LessBread
LessBread
Well, Fruny had me convinced! Actually, I started to reply by posting both the Pascal code and the C code for the PEX sample plugin and asking Fruny to explain how it was that the C based plugin worked also. Then I took a look at PEX with the Dependency Walker and saw that it imported OLEAUT32.DLL and made calls to various COM related string manipulation functions - SysAllocStringLen, SysFreeString among others - at which point I figured Fruny was correct so I let it ride. I usually keep in fairly close contact with the PEX authors but my last email to them has gone unanswered for nearly a week now - otherwise, I would fire off a question to them and find out for certain.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Fruny
Fruny
quote:
Original post by Eli Gottlieb
Thank you LessBread. Fruny, you have no idea what the question was.


Why do you think Delphi (even back in version 4, which I own) provides a facility to create a COM type library. Why do you think MS made such a big deal of touting the cross-language compatibility of its .NET platform.

"There is no joy greater than soaring high on the wings of your dreams, except maybe the joy of watching a dreamer who has nowhere to land but in the ocean of reality."

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Shannon Barber
Shannon Barber
quote:
Original post by Fruny
No.

For example, C strings are NULL-terminated, while Pascal strings hold the length of the string in their first byte. Therefore, you cannot pass a C string to a Pascal function, and conversely.

You have to use a framework like COM or CORBA that do the translation for you.


Oh common, it took me all of 2 minutes and 12second to write a ShortString class in C++ that perfectly emulates Delphi''s shortstring struct.

It''s also completely possible to vector to Delphi __fastcall''s from MSVC (unlike what is plastered all over the web by API dweebs). That took me all of 30minutes to reverse engineer - they use a very logical pattern, and after the first three, I didn''t need to disassemble any more example Delphi code to figure out how the parameters are passed.

Now, if I had had the choice[i] I _would_ have used COM - but it''s not like it''s impossible to make C++ talk Delphi''s language.
It''s not transparent, nor easily maintainable, but it is possible.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.