Re: C# to Delphi
It's not a few hours, but 2 or 3 days and you should easily get it done (at least, I'd consider investigating it). Maybe for you, but I am not so sure about it myself. I think that I would rather try out my existing options first to see how they try out. system.security.cryptography already supports rijndale and sha-1. I am aware that sha-1 has issues but this is a legacy application so I am kind of stuck with it. Bouncy Castle (http://www.bouncycastle.org/csharp/) has support for Elliptic Curve but I am not sure how close that would be to what the Delphi developer actually wrote. While there are standards in implementing these algorithms, not everyone implements them in an identical fashion, especially if that developer did so years ago and is no longer available to ask. Regards Peter On 15/12/2010 3:38 PM, silky wrote: It's not a few hours, but 2 or 3 days and you should easily get it done (at least, I'd consider investigating it).
Re: C# to Delphi
Hi Peter, I found myself in a similar situation a while ago (wanting to pass strings between a Delphi DLL and .NET). There was something slightly tricky about strings but it wasn't too bad. I think I did something with allocating memory which may be similar to your need to store the xml in memory on the Delphi side. Unfortunately I can't remember the details right now and I've since changed jobs. I remember making a demo app in my spare time as a proof of concept before implementing it at work. I'll have a look for the demo app tonight and let you know. Cheers, Matt. On Wed, Dec 15, 2010 at 4:00 PM, Peter Maddin petermad...@aapt.net.auwrote: I have some cipher units written for Delphi 7. These are fairly complex (at least for me). They contain methods (sorry functions and procedures) for the elliptic curve asymmetric cipher, The Rijndael symmetric cipher and the SHA-1 hash. The system that uses these is using file downloads and uploads using Delphi 7 Isapi dlls. The system while working, is suffering congestion problems especially with uploads. What I would like to use is WCF web services to handle data downloads and create local server files from parameters sent to the WCF web service on the server rather than perform uploads (the file contents is very small). Writing the WCF should not be too much of a challenge but I need to use the delphi code to handle decryption/encryption. I thought of writing a Win32 dll for the encryption logic called from C# WinForms (or maybe WPF) application. Has anyone done this sort of thing before? I understand that value types are ok to exchange but reference types are a pain, this includes strings. I have googled and there is a fair bit out there. Most of this is dealing with the pain of trying do it. I only need to exchange ints, bools and strings. Nothing too fancy. Has anyone some sample code they would be willing to share? Also I would like be able call a method in the dll to store information in memory to be used by other method calls. This information is stored in an xml file and I would rather it be read and processed once rather than repeat this each time I need to use a method. In other words in using delphi dll, will it preserve state between method calls? If I can't get the dll to work I will fall back on the crypographic support in the framework but this basically triples the effort required and data encrypted by the current system will not be compatible with the framework cryptographic routines. Any help very much appreciated.
Re: C# to Delphi
Thanks. That is very helpful. I'll test it out tomorrow. Do know if you call a method in the dll that stores data in global variables, that these are preserved. May need to allocate some memory to store the data but even then one must be able to maintain a pointer to it. I would like to be able to maintain some level of state between calls to the dll. I suppose I could just try this out but if you know that would be helpful. Very much appreciated. Peter. On 15/12/2010 8:53 PM, Matt Siebert wrote: Hi Peter, I found the code for the demo app. Unfortunately its a little more basic than I remember. On the Delphi side I have TestLib.dpr with... library TestLib; uses SysUtils, Classes, Windows; {$R *.res} function TestStringConverter(InputString : PChar; OutputString : PChar; BufSize : Integer) : Integer; stdcall; var Input : String; Output : String; OutputLength : Integer; begin Input := InputString; // Do something with the input string while Length(Output) (BufSize - Length(Input)) do begin Output := Output + Input; end; // Write to output buffer StrPCopy(OutputString, Output); Result := Length(Output); end; exports TestStringConverter name 'TestStringConverter'; begin end. From memory, the key was using *PChar*'s and *stdcall*. In .NET I had: [DllImport(TestLib.dll)] public static extern int TestStringConverter(string intput,StringBuilder buffer,int bufSize); void Test() { StringBuilder buffer =new StringBuilder(20); int result = TestStringConverter(Foo, buffer, buffer.Capacity); string message =string.Format(Result = {0}\n\nBuffer:\n{1}, result, buffer.ToString()); MessageBox.Show(message); } In the production code we were passing a filename to the Delphi function, which would read the contents of the file, convert it (the bit we didn't have time to port to .NET) and then pass the converted contents back to the .NET app as a string. I think the first approach was to allocate the memory in Delphi and then copy the data in .NET but then we had to call another function in the Delphi library to cleanup (I can't remember the specifics). This worked ok but in the end I think we just used the above approach to allocate a buffer in .NET and pass it to the Delphi function. We were dealing with lots of small files so making the buffer large enough wasn't an issue, although we did have to check the return value to see if the buffer was too small (if so then make a bigger one and try again). I hope this helps. Ping me off list if you'd like the full code for the demo app (not much more than what I've pasted above). Maybe some of the guys I used to work with might be willing to take a look at the code and offer some insight. Cheers. On Wed, Dec 15, 2010 at 7:30 PM, Peter Maddin petermad...@aapt.net.au mailto:petermad...@aapt.net.au wrote: I would very much appreciate a copy of your demo if you can locate it. Thanks for the offer. I was going to write up a limited dummy dll for proof of concept. If that did not work, try COM. I have a text Delphi COM Programming by Eric Harmon buts its pretty ancient (but then so is the Delphi code I am looking at) I have not had much exposure to COM. My only endeavour has been to write one using C# for use by Access VBA. That was a very simple hash function for passwords. It worked ok but I don't think they have ever used it. On 15/12/2010 5:03 PM, Matt Siebert wrote: Hi Peter, I found myself in a similar situation a while ago (wanting to pass strings between a Delphi DLL and .NET). There was something slightly tricky about strings but it wasn't too bad. I think I did something with allocating memory which may be similar to your need to store the xml in memory on the Delphi side. Unfortunately I can't remember the details right now and I've since changed jobs. I remember making a demo app in my spare time as a proof of concept before implementing it at work. I'll have a look for the demo app tonight and let you know. Cheers, Matt. On Wed, Dec 15, 2010 at 4:00 PM, Peter Maddin petermad...@aapt.net.au mailto:petermad...@aapt.net.au wrote: I have some cipher units written for Delphi 7. These are fairly complex (at least for me). They contain methods (sorry functions and procedures) for the elliptic curve asymmetric cipher, The Rijndael symmetric cipher and the SHA-1 hash. The system that uses these is using file downloads and uploads using Delphi 7 Isapi dlls. The system while working, is suffering congestion problems especially with uploads. What I would like to use is WCF web services to handle data downloads and create local server files from parameters sent to the WCF
Re: C# to Delphi
I'm not sure about the globals. I did have success with allocating the buffer in Delphi, then cleaning it up in a separate call but can't remember if the Delphi code kept a reference to the buffer, or if the .NET code passed it into the cleanup call. On Wed, Dec 15, 2010 at 11:11 PM, Peter Maddin petermad...@aapt.net.auwrote: Thanks. That is very helpful. I'll test it out tomorrow. Do know if you call a method in the dll that stores data in global variables, that these are preserved. May need to allocate some memory to store the data but even then one must be able to maintain a pointer to it. I would like to be able to maintain some level of state between calls to the dll. I suppose I could just try this out but if you know that would be helpful. Very much appreciated. Peter. On 15/12/2010 8:53 PM, Matt Siebert wrote: Hi Peter, I found the code for the demo app. Unfortunately its a little more basic than I remember. On the Delphi side I have TestLib.dpr with... library TestLib; uses SysUtils, Classes, Windows; {$R *.res} function TestStringConverter(InputString : PChar; OutputString : PChar; BufSize : Integer) : Integer; stdcall; var Input : String; Output : String; OutputLength : Integer; begin Input := InputString; // Do something with the input string while Length(Output) (BufSize - Length(Input)) do begin Output := Output + Input; end; // Write to output buffer StrPCopy(OutputString, Output); Result := Length(Output); end; exports TestStringConverter name 'TestStringConverter'; begin end. From memory, the key was using *PChar*'s and *stdcall*. In .NET I had: [DllImport(TestLib.dll)] public static extern int TestStringConverter(string intput, StringBuilder buffer, int bufSize); void Test() { StringBuilder buffer = new StringBuilder(20); int result = TestStringConverter(Foo, buffer, buffer.Capacity); string message = string.Format(Result = {0}\n\nBuffer:\n{1}, result, buffer.ToString()); MessageBox.Show(message); } In the production code we were passing a filename to the Delphi function, which would read the contents of the file, convert it (the bit we didn't have time to port to .NET) and then pass the converted contents back to the .NET app as a string. I think the first approach was to allocate the memory in Delphi and then copy the data in .NET but then we had to call another function in the Delphi library to cleanup (I can't remember the specifics). This worked ok but in the end I think we just used the above approach to allocate a buffer in .NET and pass it to the Delphi function. We were dealing with lots of small files so making the buffer large enough wasn't an issue, although we did have to check the return value to see if the buffer was too small (if so then make a bigger one and try again). I hope this helps. Ping me off list if you'd like the full code for the demo app (not much more than what I've pasted above). Maybe some of the guys I used to work with might be willing to take a look at the code and offer some insight. Cheers. On Wed, Dec 15, 2010 at 7:30 PM, Peter Maddin petermad...@aapt.net.auwrote: I would very much appreciate a copy of your demo if you can locate it. Thanks for the offer. I was going to write up a limited dummy dll for proof of concept. If that did not work, try COM. I have a text Delphi COM Programming by Eric Harmon buts its pretty ancient (but then so is the Delphi code I am looking at) I have not had much exposure to COM. My only endeavour has been to write one using C# for use by Access VBA. That was a very simple hash function for passwords. It worked ok but I don't think they have ever used it. On 15/12/2010 5:03 PM, Matt Siebert wrote: Hi Peter, I found myself in a similar situation a while ago (wanting to pass strings between a Delphi DLL and .NET). There was something slightly tricky about strings but it wasn't too bad. I think I did something with allocating memory which may be similar to your need to store the xml in memory on the Delphi side. Unfortunately I can't remember the details right now and I've since changed jobs. I remember making a demo app in my spare time as a proof of concept before implementing it at work. I'll have a look for the demo app tonight and let you know. Cheers, Matt. On Wed, Dec 15, 2010 at 4:00 PM, Peter Maddin petermad...@aapt.net.auwrote: I have some cipher units written for Delphi 7. These are fairly complex (at least for me). They contain methods (sorry functions and procedures) for the elliptic curve asymmetric cipher, The Rijndael symmetric cipher and the SHA-1 hash. The system that uses these is using file downloads and uploads using Delphi 7 Isapi dlls. The system while working, is suffering congestion problems
[OT] Stuxnet architecture
http://www.symantec.com/content/en/us/enterprise/media/security_response/whi tepapers/w32_stuxnet_dossier.pdf I found a link to this PDF via Bruce Schneier's Crytogram http://www.schneier.com/crypto-gram.html newsletter. The 'Stuxnet Architecture' section of the document describes how the malware using a staggering variety of advanced techniques to load, conceal and propagate. It's fascinating reading for Windows developers. I always wondered what would happen if professionals decided to write a virus ... and now I think we have. Although, in this case it's more than just clever code, there is some espionage involved as well. In the summary the author says Stuxnet is the type of threat we hope to never see again. Greg
[OT] - Any interesting projects happening?
Is anyone working on anything particularly interesting? If so, hopefully you will come to MXUG: https://groups.google.com/group/mxug?hl=enpli=1 and talk about it! Somebody must be working on some new tool to revolutionise something or other, right? -- silky http://dnoondt.wordpress.com/ Every morning when I wake up, I experience an exquisite joy — the joy of being this signature.
RE: C# to Delphi (more accurately - Delphi to C#)
Peter You have the VCL controls for the Delphi app, I suppose (you said you had the source)? There is a question (with an acceptable solution) on Experts Exchange here http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_23707 698.html - but unless a member, you won't be able to judge its usefulness. Embedding VCL (Win32) control on external C# application form Asked by http://www.experts-exchange.com/M_1437683.html roknjohn in Delphi Programming, .NET, C# Programming Language Tags: http://www.experts-exchange.com/tag/Delphi%2C+C%23#allResults Delphi, C# I have two applications, one written in C# (Windows Forms) and the other in Delphi (Win32). Is it possible to render a TPanel (or other component) within the running Delphi application onto some container control within the C# application? I've tried using the SetParent API function, but this results in a OutOfMemory runtime exception in the C# app. However, I am able to embed the entire Delphi app's main form on the C# app, using SetParent, but I would like to only embed a portion, TPanel/TFrame. I recall that someone on this list uses Experts Exchange. _ Ian Thomas Victoria Park, Western Australia _ From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Peter Maddin Sent: Thursday, December 16, 2010 9:33 AM To: ozDotNet Subject: Re: C# to Delphi I tried using TurnSharp but this is really expecting a standard Delphi project (dpr) file. The code I needed to convert is a control (dpk) file. This is not a selectable option. I converted the demo project that uses this control and it claimed 93.8%. I checked the generated code and the critical code for the EllipticCurve was not present (In truth I did not expect it to be as this is a control integrated into the IDE) I would have to spend some time taking the control code and making it a standard unit within a delphi project. I would then have to do the same with all the other controls needed. While this is do-able I have not coded in Delphi for quite a few years and then the outcome may or may not provide a viable product. I think this might take up to a week to do with an uncertain outcome. At this stage I think the dll /COM is a more viable option. On 15/12/2010 2:10 PM, Ian Thomas wrote: Peter Had you considered a Delphi to C# code converter? There's one (TurnSharp https://www.turnsharp.com/delphi-to-csharp.aspx ) that supports .NET 4.0 Framework and money-back if not 90%+ (not a great metric, really), with a trial version. _ Ian Thomas Victoria Park, Western Australia _ From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Peter Maddin Sent: Wednesday, December 15, 2010 2:00 PM To: ozDotNet Subject: C# to Delphi I have some cipher units written for Delphi 7.
Re: C# to Delphi (more accurately - Delphi to C#)
Thanks for the suggestion. I think a dll would be less effort but this could be another option. Use to have an Experts Exchange account. I needed this to solve a particular problem, once I had the solution I did not have much further use for it and it lapsed. I think it has a free trial period. I will consider this if the other directions I have become dead ends. On 16/12/2010 9:59 AM, Ian Thomas wrote: Peter You have the VCL controls for the Delphi app, I suppose (you said you had the source)? There is a question (with an acceptable solution) on Experts Exchange here http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_23707698.html -- but unless a member, you won't be able to judge its usefulness. *Embedding VCL (Win32) control on external C# application form* *Asked by roknjohn http://www.experts-exchange.com/M_1437683.html in Delphi Programming, .NET, C# Programming Language* *Tags: Delphi, C# http://www.experts-exchange.com/tag/Delphi%2C+C%23#allResults* I have two applications, one written in C# (Windows Forms) and the other in Delphi (Win32). Is it possible to render a TPanel (or other component) within the running Delphi application onto some container control within the C# application? I've tried using the SetParent API function, but this results in a OutOfMemory runtime exception in the C# app. However, I am able to embed the entire Delphi app's main form on the C# app, using SetParent, but I would like to only embed a portion, TPanel/TFrame. I recall that someone on this list uses Experts Exchange. Ian Thomas Victoria Park, Western Australia *From:*ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] *On Behalf Of *Peter Maddin *Sent:* Thursday, December 16, 2010 9:33 AM *To:* ozDotNet *Subject:* Re: C# to Delphi I tried using TurnSharp but this is really expecting a standard Delphi project (dpr) file. The code I needed to convert is a control (dpk) file. This is not a selectable option. I converted the demo project that uses this control and it claimed 93.8%. I checked the generated code and the critical code for the EllipticCurve was not present (In truth I did not expect it to be as this is a control integrated into the IDE) I would have to spend some time taking the control code and making it a standard unit within a delphi project. I would then have to do the same with all the other controls needed. While this is do-able I have not coded in Delphi for quite a few years and then the outcome may or may not provide a viable product. I think this might take up to a week to do with an uncertain outcome. At this stage I think the dll /COM is a more viable option. On 15/12/2010 2:10 PM, Ian Thomas wrote: Peter Had you considered a Delphi to C# code converter? There's one (TurnSharp https://www.turnsharp.com/delphi-to-csharp.aspx) that supports .NET 4.0 Framework and money-back if not 90%+ (not a great metric, really), with a trial version. Ian Thomas Victoria Park, Western Australia *From:*ozdotnet-boun...@ozdotnet.com mailto:ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] *On Behalf Of *Peter Maddin *Sent:* Wednesday, December 15, 2010 2:00 PM *To:* ozDotNet *Subject:* C# to Delphi I have some cipher units written for Delphi 7.
RE: C# to Delphi (more accurately - Delphi to C#)
(OT- On Experts Exchange) If you just want to read the answers, visit the page with Google as a referrer and scroll all the way down. John Date: Thu, 16 Dec 2010 10:08:10 +0800 From: petermad...@aapt.net.au To: ozdotnet@ozdotnet.com Subject: Re: C# to Delphi (more accurately - Delphi to C#) Thanks for the suggestion. I think a dll would be less effort but this could be another option. Use to have an Experts Exchange account. I needed this to solve a particular problem, once I had the solution I did not have much further use for it and it lapsed. I think it has a free trial period. I will consider this if the other directions I have become dead ends. On 16/12/2010 9:59 AM, Ian Thomas wrote: Peter You have the VCL controls for the Delphi app, I suppose (you said you had the source)? There is a question (with an acceptable solution) on Experts Exchange here – but unless a member, you won’t be able to judge its usefulness. Embedding VCL (Win32) control on external C# application form Asked by roknjohn in Delphi Programming, .NET, C# Programming Language Tags: Delphi, C# I have two applications, one written in C# (Windows Forms) and the other in Delphi (Win32). Is it possible to render a TPanel (or other component) within the running Delphi application onto some container control within the C# application? I've tried using the SetParent API function, but this results in a OutOfMemory runtime exception in the C# app. However, I am able to embed the entire Delphi app's main form on the C# app, using SetParent, but I would like to only embed a portion, TPanel/TFrame. I recall that someone on this list uses Experts Exchange. Ian Thomas Victoria Park, Western Australia From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Peter Maddin Sent: Thursday, December 16, 2010 9:33 AM To: ozDotNet Subject: Re: C# to Delphi I tried using TurnSharp but this is really expecting a standard Delphi project (dpr) file. The code I needed to convert is a control (dpk) file. This is not a selectable option. I converted the demo project that uses this control and it claimed 93.8%. I checked the generated code and the critical code for the EllipticCurve was not present (In truth I did not expect it to be as this is a control integrated into the IDE) I would have to spend some time taking the control code and making it a standard unit within a delphi project. I would then have to do the same with all the other controls needed. While this is do-able I have not coded in Delphi for quite a few years and then the outcome may or may not provide a viable product. I think this might take up to a week to do with an uncertain outcome. At this stage I think the dll /COM is a more viable option. On 15/12/2010 2:10 PM, Ian Thomas wrote: Peter Had you considered a Delphi to C# code converter? There’s one (TurnSharp) that supports .NET 4.0 Framework and money-back if not 90%+ (not a great metric, really), with a trial version. Ian Thomas Victoria Park, Western Australia From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Peter Maddin Sent: Wednesday, December 15, 2010 2:00 PM To: ozDotNet Subject: C# to Delphi I have some cipher units written for Delphi 7.
Re: C# to Delphi (more accurately - Delphi to C#)
Thanks. I give it a go. On 16/12/2010 10:11 AM, John Li wrote: (OT- On Experts Exchange) If you just want to read the answers, visit the page with Google as a referrer and scroll all the way down. John Date: Thu, 16 Dec 2010 10:08:10 +0800 From: petermad...@aapt.net.au To: ozdotnet@ozdotnet.com Subject: Re: C# to Delphi (more accurately - Delphi to C#) Thanks for the suggestion. I think a dll would be less effort but this could be another option. Use to have an Experts Exchange account. I needed this to solve a particular problem, once I had the solution I did not have much further use for it and it lapsed. I think it has a free trial period. I will consider this if the other directions I have become dead ends. On 16/12/2010 9:59 AM, Ian Thomas wrote: Peter You have the VCL controls for the Delphi app, I suppose (you said you had the source)? There is a question (with an acceptable solution) on Experts Exchange here – but unless a member, you won’t be able to judge its usefulness. Embedding VCL (Win32) control on external C# application form Asked by roknjohn in Delphi Programming, .NET, C# Programming Language Tags: Delphi, C# I have two applications, one written in C# (Windows Forms) and the other in Delphi (Win32). Is it possible to render a TPanel (or other component) within the running Delphi application onto some container control within the C# application? I've tried using the SetParent API function, but this results in a OutOfMemory runtime exception in the C# app. However, I am able to embed the entire Delphi app's main form on the C# app, using SetParent, but I would like to only embed a portion, TPanel/TFrame. I recall that someone on this list uses Experts Exchange. Ian Thomas Victoria Park, Western Australia From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Peter Maddin Sent: Thursday, December 16, 2010 9:33 AM To: ozDotNet Subject: Re: C# to Delphi I tried using TurnSharp but this is really expecting a standard Delphi project (dpr) file. The code I needed to convert is a control (dpk) file. This is not a selectable option. I converted the demo project that uses this control and it claimed 93.8%. I checked the generated code and the critical code for the EllipticCurve was not present (In truth I did not expect it to be as this is a control integrated into the IDE) I would have to spend some time taking the control code and making it a standard unit within a delphi project. I would then have to do the same with all the other controls needed. While this is do-able I have not coded in Delphi for quite a few years and then the outcome may or may not provide a viable product. I think this might take up to a week to do with an uncertain outcome. At this stage I think the dll /COM is a more viable option. On 15/12/2010 2:10 PM, Ian Thomas wrote: Peter Had you considered a Delphi to C# code converter? There’s one (TurnSharp) that supports .NET 4.0 Framework and money-back if not 90%+ (not a great metric, really), with a trial version. Ian Thomas Victoria Park, Western Australia From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Peter Maddin Sent: Wednesday, December 15, 2010 2:00 PM To: ozDotNet Subject: C# to Delphi I have some cipher units written for Delphi 7.
[OT] Looking for direction with VS 2010 Add-in for Database Projects
Greetings (and I apologise for the long post), I'm trying to write an Add-in for VS 2010 to provide some automation in database projects. I've received some help from the MSDN forums but I'd like to get opinions from those of you who may have gone down this road before. We have some complex database projects with many dependencies. The projects are designed to be components for other database solutions and are themselves made up of components. We need to deploy to external networks and have elected to set the Deploy action to Create a deployment script (.sql). The solution consists of a number of separate projects that make up the components of the system. Some target deployment environments will receive some of these components whilst different deployment targets will receive a different mix of components. To support this we use the Deployment Project method. We have a database project that holds the pre post deployment scripts and only references to the component projects. When deploying a release project the DBA has to do the following:- Open the solution and select the particular deployment project. Check that the project .sqldeployment file has the correct settings and set the target connection string and target database for the deployment. Open each referenced project and ensure that the .sqldeployment and database connection settings are correct in each one. Point the release at a copy of the target production database version and deploy. The output window will show the deployment order for each of the referenced projects. The resultant .sql scripts are then executed in that order against the copy of production and verified as deployed correctly. These scripts are them shipped over to the production environment and executed against each of the production databases. The parts that I would like to automate are the tedious comparisons of the .sqldeployment settings and the target database connection settings. I can use the DTE object model to find the .sql deployment files in each of the referenced projects and do a simple comparison of the settings from the xml therein. I will be able to show a report on the differences so the DBA can take appropriate action. I did not seem to be able to find the TargetConnectionString and TargetDatabase properties, which are stored in the .dbproj file, using either the automation objects or the configuration manager objects. I was advised, on the MSDN forums, to use the MSBuild object model instead. This works fine and I will be able to include comparisons of these settings in my report page. The big problem is that there seems to be no way of editing the connection properties without the IDE detecting the change and prompting for a reload of the project(s). This can take many minutes, whilst the database models are rebuilt, and I'd like to avoid this. These properties can be edited in the IDE through the project properties pages without triggering a reload and I'd be very grateful if I could find a similar way using some sort of automation. -- Regards, noonie
Re: C# to Delphi
Hi Matt Worked fine first time. Thanks for the code. I have Delphi 7 in VM (XP Pro) but have managed to install Delphi 2007 (have Delphi 2009 but that uses Unicode and I expect that will cause me grief with legacy code this old). I have installed my three cipher controls in Delphi 2007 and then used Delphi 2007 to build your basic dll to be consumed by my elementary C# winforms app. So far so good. I really miss Resharper ( I am working at home). On 15/12/2010 8:53 PM, Matt Siebert wrote: Hi Peter, I found the code for the demo app. Unfortunately its a little more basic than I remember. On the Delphi side I have TestLib.dpr with... library TestLib; uses SysUtils, Classes, Windows; {$R *.res} function TestStringConverter(InputString : PChar; OutputString : PChar; BufSize : Integer) : Integer; stdcall; var Input : String; Output : String; OutputLength : Integer; begin Input := InputString; // Do something with the input string while Length(Output) (BufSize - Length(Input)) do begin Output := Output + Input; end; //Write to output buffer StrPCopy(OutputString, Output); Result := Length(Output); end; exports TestStringConverter name 'TestStringConverter'; begin end. From memory, the key was using PChar's andstdcall. In .NET I had: [DllImport("TestLib.dll")] publicstaticexternintTestStringConverter(stringintput,StringBuilderbuffer,intbufSize); voidTest() { StringBuilderbuffer=newStringBuilder(20); intresult=TestStringConverter("Foo",buffer,buffer.Capacity); stringmessage=string.Format("Result={0}\n\nBuffer:\n{1}",result,buffer.ToString()); MessageBox.Show(message); } In the production code we were passing a filename to the Delphi function, which would read the contents of the file, convert it (the bit we didn't have time to port to .NET) and then pass the converted contents back to the .NET app as a string. I think the first approach was to allocate the memory in Delphi and then copy the data in .NET but then we had to call another function in the Delphi library to cleanup (I can't remember the specifics). This worked ok but in the end I think we just used the above approach to allocate a buffer in .NET and pass it to the Delphi function. We were dealing with lots of small files so making the buffer large enough wasn't an issue, although we did have to check the return value to see if the buffer was too small (if so then make a bigger one and try again). I hope this helps. Ping me off list if you'd like the full code for the demo app (not much more than what I've pasted above). Maybe some of the guys I used to work with mightbe willing to take a look at the code and offer some insight. Cheers. On Wed, Dec 15, 2010 at 7:30 PM, Peter Maddin petermad...@aapt.net.au wrote: I would very much appreciate a copy of your demo if you can locate it. Thanks for the offer. I was going to write up a limited dummy dll for proof of concept. If that did not work, try COM. I have a text "Delphi COM Programming" by Eric Harmon buts its pretty ancient (but then so is the Delphi code I am looking at) I have not had much exposure to COM. My only endeavour has been to write one using C# for use by Access VBA. That was a very simple hash function for passwords. It worked ok but I don't think they have ever used it. On 15/12/2010 5:03 PM, Matt Siebert wrote: Hi Peter, I found myself in a similar situation a while ago (wanting to pass strings between a Delphi DLL and .NET). There was something slightly
Re: C# to Delphi
Hi Matt Found this concerning state management with a Delphi dll http://stackoverflow.com/questions/1042686/delphi-dynamic-dll-global-variable The best options look like 1. Use a second dll that is loaded dynamically (and unload it when done). 2. Use COM There is also LoadLibraryEx and FreeLibrary (http://msdn.microsoft.com/en-us/library/ms684179(v=VS.85).aspx http://msdn.microsoft.com/en-us/library/ms684179%28v=VS.85%29.aspx) On 15/12/2010 9:42 PM, Matt Siebert wrote: I'm not sure about the globals. I did have success with allocating the buffer in Delphi, then cleaning it up in a separate call but can't remember if the Delphi code kept a reference to the buffer, or if the .NET code passed it into the cleanup call.