Results 1 to 12 of 12

Thread: [RESOLVED] [2.0] Calling function from Delphi DLL

  1. #1

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Resolved [RESOLVED] [2.0] Calling function from Delphi DLL

    I get the message "A reference to <path> could not be added. Please make sure the file is accessible, and that it is a valid assembly or COM component" any ideas what could be the problem? And how can i get it working via P/Invoke?
    Last edited by Paul M; Jan 5th, 2008 at 01:37 AM. Reason: Change title to be more relevant!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2.0] Add reference to Delphi DLL

    Is this DLL a .NET assembly or a COM component? If it's neither then you can't add a reference to it, as the error message suggests. I'm not quite sure why you're asking about PInvoke. If you know you need to access its methods via PInvoke then why are you trying to add a reference to it? If it's not a .NET assembly or a COM component then you invoke its methods exactly the same way you do any other: using the DllImport attribute on a static method declaration.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] Add reference to Delphi DLL

    Unable to load DLL 'Encrypter.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
    Thats what i get now, after having manually registered the DLL and declaring it. Must it be placed in the System or System32 folder?

    <edit>
    I placed it in the System32 folder and i don't get that error anymore. No i get the following...

    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    Last edited by Paul M; Jan 5th, 2008 at 01:00 AM.

  4. #4

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] Add reference to Delphi DLL

    Could it be that the String type of .NET is not equivalent to that of Delphi's?

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Calling function from Delphi DLL

    Show us the function signature (from the Delphi code) and the DllImport line from the C# code.

  6. #6

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] Calling function from Delphi DLL

    Code:
    function EncryptDoc(Password, FilePath, LaunchFile, OutputFile : WideString) : LongBool; stdcall;
    Thats the definition of the function in the Delphi DLL and below is the DllImport from C#...

    Code:
    [DllImport("Encrypter.dll")]
    static extern bool EncryptDoc(string PassWord, string FilePath, string LaunchFile, string OutputFile);
    <Edit>
    It uses Delphi WideString type which is equivalent to the .NET string type (System.String or BSTR), and Delphi LongBool which is equivalent to .NET Boolean.
    Last edited by Paul M; Jan 5th, 2008 at 07:32 PM.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2.0] Calling function from Delphi DLL

    Does the ": WideString" in the parameter list imply that all four parameters are that type?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] Calling function from Delphi DLL

    Yes they are all WideString's

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2.0] Calling function from Delphi DLL

    I can honestly say that I can't see any obvious issue there.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] Calling function from Delphi DLL



    There is a screen shot of what i am getting but its totally got me stumped

  11. #11

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] Calling function from Delphi DLL

    Should the WideString's be PChar's instead, anybody know?

  12. #12

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] Calling function from Delphi DLL

    Quote Originally Posted by Paul M
    Should the WideString's be PChar's instead, anybody know?
    That fixed it

    Just as i fixed it Australia got 2 wickets in a row !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width