AW: Converting C/C++ DLL to Delphi
Luc Knaepkens-Düllberg <[email protected]>
| Newsgroups | gmane.comp.lang.delphi.jedi |
|---|---|
| Message-ID | <[email protected]> |
Delphi structures are incompatible to c structures. Especially when you use "packed structures" in c. I tried a lot of stuff with it, and it was purely chaos. I turned down to use simple variables like int, pchar, etc... Which is in no way a structured method of working... -----Ursprüngliche Nachricht----- Von: rekorbima [mailto:[email protected]] Gesendet: Samstag, 11. September 2004 14:01 An: [email protected] Betreff: [Delphi-JEDI] Converting C/C++ DLL to Delphi I am trying to call communicate with an (written in Visual C/C++) from a Delphi DLL. I wish to both export my dll functions back to the main C app, and also call some of the C functions that the main app is offering to my dll. The first problem I'm having: Using Delphi's cdecl convention seems to work fine for passing parameters, but unfortunately getting the calling convention synchronized is only half the battle. The way that return values from functions get passed, also seems to need to be compatible, and I don't see any options in Delphi to set that. Specifically, there is an 8-byte structure that needs to be sent both ways: returned by the called C functions to the Delphi dll. Conversely, the structure is also returned from exported Delphi functions back to the main app. My understanding, possibly wrong, is that C functions return 8-byte structures very differently than Delphi functions do. Supposedly, C returns them through the edx:eax register pair, but Delphi returns them through a combination of eax and a different, incompatible method. I'm trying to come up with a way to get the two languages to talk to each other that does not involve using assembly code to manually read or assign values to the registers. I do not understand assembly code, nor am I a very good programmer, and while I'm not opposed to learning something new, I would vastly prefer the ease and conciseness of straight OP. 1) Regarding returning an 8-byte structure from a Delphi function to the C main app, would it be sufficient to declare the Delphi function as returning an int64 (instead of the 8-byte structure that the Delphi function is actually returning)? In some obscure docs I noticed that Delphi returns the int64 using the (compatible with C's return convention?) edx:eax pair to return 64-bit values. Wouldn't it make sense to, in the Delphi function, simply typecast (or use a variant record to change) the 8-byte structure to "int64" at the last moment, just as it's being assigned to the function's "return" variable? Would doing this let the Delphi compiler know that I want my Delphi functions to return the 64-bit structure back to the C main app, by using edx:eax instead of Delphi's normal incompatible way of returning 8-byte structures? 2) Regarding returning an 8-byte structure from the main app's C functions to the Delphi DLL, isn't there some simple way in Delphi coding to assign the return value to a 64-bit Delphi data type? My understanding is that because C returns the structure in eax:edx mean that a Delphi 64-bit variable will never properly receive the structure using standard OP code like: var resultvalue : int64; begin resultvalue := (int64)CFunctionThatReturns8ByteStructure(); Is it really necessary to instead use assembly code to read eax and edx and assign their values to a Delphi 64-bit data type? Is there an OP way of getting around using assembly, in this case? Folks, I hope these questions are clear. I acknowledge having a weak grasp of the above discussion, so please feel free to point where I've been less than articulate or logical. Thanks very much for any help. -Paul ------------------------ Yahoo! Groups Sponsor --------------------~--> $9.95 domain names from Yahoo!. Register anything. http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/i7folB/TM --------------------------------------------------------------------~-> Yahoo! Groups Links ------------------------ Yahoo! Groups Sponsor --------------------~--> $9.95 domain names from Yahoo!. Register anything. http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/i7folB/TM --------------------------------------------------------------------~-> Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/Delphi-JEDI/ <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/