-1

I have a delphi dll which i call using interop services in my web app. The The web app im calling the dll in Platform target is set to any cpu. When i test it in my console app which Platform target is x86 it loads and calls the dll with no errors. If i change the console apps platform target to any cpu it gives that same error. I cannot change the platform target of the web app. How can i overcome this? Is it that the delphi dll is targeted at using x86. Can i compile the delphi project to use any cpu in Borland Delphi 7. Help is much appreciated. Here is my import statement-

    [DllImport(@"Decoder.dll", CharSet = CharSet.Unicode)]
    static extern Int32 CALinkDecode(
        string sCode,
        out int SubscriberID,
        out int MailshotID,
        out int LinkID
    );

    Int32 retvalptr = CALinkDecode(sCode, out cas,
                                           out cam, out cal);
Lex Li
  • 60,503
  • 9
  • 116
  • 147
Lucky Luke2
  • 2,056
  • 5
  • 25
  • 32
  • Another option is to throw away the Delphi code and be pure C#. Does your webapp use any more than a single decode function? – David Heffernan May 30 '13 at 08:42
  • Just uses the delphi decode function. – Lucky Luke2 May 30 '13 at 08:44
  • Can you be specific about the function name? Exact name please. I have strong feeling you are wasting your time with Delphi when your goal is trivial to achieve with .net. – David Heffernan May 30 '13 at 08:57
  • David what happens is theres a legacy delphi app that encodes three values into a string using base32. Also a delphi dll that decodes this string and returns the three values. I want to use this decoder. – Lucky Luke2 May 30 '13 at 09:05
  • I would not do it that way. It's going to be trivial to port to .net code. – David Heffernan May 30 '13 at 09:09
  • Not really knowledgeable on decoding using base32 – Lucky Luke2 May 30 '13 at 09:13
  • base32, not base64? Well, it seems tobe rather straightforward transformation http://en.wikipedia.org/wiki/Base32 And there are readymade .Net functions for it: https://www.google.ru/search?client=opera&q=base32+.net&sourceid=opera http://www.codeproject.com/Articles/35492/Base32-encoding-implementation-in-NET http://stackoverflow.com/questions/641361/base32-decoding – Arioch 'The May 30 '13 at 11:27

2 Answers2

2

You have two options,

  • Upgrade to newer Delphi releases, so that you can recompile your library project to x64. Then it can be loaded.
  • Stick to x86 compilation, and force the web application to run in 32 bit. If the web application is hosted in IIS, you can change the application pool setting.

http://www.codeproject.com/Tips/325824/Running-a-32-bit-application-under-IIS-on-a-64-bit

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • Thanks. I think i prefer the second option. Any suggestions. I have downloaded Borland Delphi 7. – Lucky Luke2 May 30 '13 at 08:00
  • The attached CodeProject article talks about how to change IIS settings. Please try the steps out. – Lex Li May 30 '13 at 08:08
  • Sorry Lex, i meant the first option. any suggestions on free newer ide's. – Lucky Luke2 May 30 '13 at 08:39
  • Delphi is not free. You'll need to pay for the x64 compiler. Or use FPC. You cannot download Delphi 7 unless you mean the illegal pirated versions. If so, shame on you. – David Heffernan May 30 '13 at 08:44
  • Thanks David. I guess FPC it is then ;) – Lucky Luke2 May 30 '13 at 08:49
  • Im lookin at trial version of Embarcadero RAD Studio xe4 – Lucky Luke2 May 30 '13 at 08:50
  • 1
    If you're fine with feature set of Delphi 7 then perhaps usinge CodeTyphon distro of FPC would be totally enough for you. – Arioch 'The May 30 '13 at 09:15
  • @Arioch'The if i create a new pascal library and insert my delphi code, will this create a delphi library. Are they one in the same? – Lucky Luke2 May 30 '13 at 10:51
  • DLL is not Delphi library, DLL is Windows library. It is language-agnostic and only responds to Windows ABI rules. You can create it with ANY language. I just think that FPC would be most close to Delphi with Win64 support – Arioch 'The May 30 '13 at 11:02
2

Clearly you have a 32 bit DLL which cannot be loaded in a 64 bit process. Either make a 64 bit version of the DLL, or configure IIS to host your DLL in a 32 bit process.

However, I suspect that your DLL is not needed at all. You appear to be using it to perform some trivial text processing. It's probably going to be simpler just to port that to .net and avoid all this complexity. Once you've done this, you'll be free of this dependency for good.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Hi David, yes long term that is going to be the solution. Thanks for your help. – Lucky Luke2 May 30 '13 at 09:20
  • @StylesYoung then perhaps consider RemObjects Oxygen or PascalABC.Net – Arioch 'The May 30 '13 at 11:03
  • @Arioch C# is the obvious choice considering that the app is written in that language – David Heffernan May 30 '13 at 12:48
  • @DavidHeffernan to create something new and simple - yes. To port inherited code - perhaps no. At least topic-starter afraids of doin this. We did not saw the code, we don;t know how complex and low-level it might be. – Arioch 'The May 30 '13 at 12:50
  • @Arioch How complex can base 32 be? Your suggestions are the complex ones. – David Heffernan May 30 '13 at 13:04
  • @DavidHeffernan for base32 my suggestion is to just take read-made C# library. But his DLL is not merely base32 decoder - it is some unknown parser of URL. Base32 is only minor sub-set of DLL's functionality, unknown to us. – Arioch 'The May 30 '13 at 13:16
  • @Arioch Do you think it likely that .net includes URL parsing classes? – David Heffernan May 30 '13 at 14:31
  • @DavidHeffernan you mean RegExp? that would be re-implementing, not porting. The parsing is not protocol/port/server but a custom data from custom-formatted URL. `SubscriberID`, `MailshotID`, `LinkID` are not defined as URI components in HTTP RFC, are they ? – Arioch 'The May 30 '13 at 15:24
  • @Arioch Not regexp. Custom formatted URI can have any parameters you like. – David Heffernan May 30 '13 at 15:39
  • @DavidHeffernan So, can he find ready-made stock Microsoft-made code to extract "any parameters you like" from "Custom formatted URI" ? – Arioch 'The May 30 '13 at 15:40