Thursday, June 10, 2004

PInvoke and Delphi

Adam Nathan has written a PInvoke.Net Webservice - a webservice that gives you C# and VB PInvoke definitions for Win32 functions. Actually, for any DLL function that you used to access in Win32. Obviously "Header conversion" is a painful job, and we've all seen that in Delphi.

I think this is a wonderful idea. A community maintained Wiki that contains definitions of the functions you might need, and you can add your own. I just hope no one abuses this system.

There's still one tiny little problem. Since C# is so ubiquitous in the .NET world, there were way too many functions with just C# definitions, not even VB. And ZERO in Delphi, though the site is fairly language agnostic. Now this gets me thinking: John Kaster has written the BabelCode webservice using Corbin's CodeDOM engine (I guess :) ). This converts C# code to Delphi (for .NET). And it's also a webservice serving SOAP requests.

My next thought was: make an application that calls the PInvoke.net webservice, takes the C# code from there, calls the BabelCode webservice and voila, we have the equivalent Delphi PInvoke declaration. (Note: Do not try this at home) Being me, I couldn't resist this - and being me, I had to write it in Delphi 7. It's all done and all that - available at http://www.agnisoft.com/downloads/pbroker.zip. Check it out, tell me what you think.

4 Comments:

Anonymous Anonymous said...

Nice result! However the controls are anchored and in large fonts mode in XP you have no access to the buttons, bar tabbing and guessing. Common problem, I know :-)

- Brian Long

5:42 AM  
Blogger Deepak Shenoy said...

Have set :

Scaled := False;

I've uploaded a new build to http://www.agnisoft.com/downloads/pbroker.zip.

Thanks for that, Brian! I tested it on my laptop but let me know if anything's still awry.

5:20 AM  
Anonymous Anonymous said...

Looks good now. Does the Web Service offer any way of accessing the dependant structures used in the parameter list? Take CreateProcess for example. I know we have that one supplied in Borland.Vcl.Windows.pas, but if we didn't, how would we get the definition for SECURITY_ATTRIBUTES, STARTUPINFO and PROCESS_INFORMATION?

2:27 AM  
Blogger Deepak Shenoy said...

The site does have the information, but unfortunately it isn't available to the web service. These seem to be "Definitions" and therefore unavailable to the SOAP client - but you can search on http://www.pinvoke.net.

3:28 AM  

Post a Comment

<< Home