Calling a Delphi DLL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kelvin.koogan@googlemail.com

    Calling a Delphi DLL

    How can I call a function in a Delphi DLL from C++/CLI?

    The Delphi function is declared as follows:

    function Func1(IsDsb: Boolean; FirstStr, SecondStr : String): String;

    I've tried

    [DllImport("mydl l", EntryPoint="Fun c1")]
    extern "C" char *Func1(int isDsb, char *firstString, char
    *secondString);

    Func1(0, "kl;kl;sdfk ", "kdlks;ldfk ");

    but I get an access violation. What should I be doing?

    What calling convention will the Delphi function use? Does it need to
    have stdcall added?

    TIA,
    KK
  • Cholo Lennon

    #2
    Re: Calling a Delphi DLL

    kelvin.koogan@g ooglemail.com wrote:
    How can I call a function in a Delphi DLL from C++/CLI?
    >
    The Delphi function is declared as follows:
    >
    function Func1(IsDsb: Boolean; FirstStr, SecondStr : String): String;
    >
    I've tried
    >
    [DllImport("mydl l", EntryPoint="Fun c1")]
    extern "C" char *Func1(int isDsb, char *firstString, char
    *secondString);
    >
    Func1(0, "kl;kl;sdfk ", "kdlks;ldfk ");
    >
    but I get an access violation. What should I be doing?
    >
    What calling convention will the Delphi function use? Does it need to
    have stdcall added?
    >
    In Delphi you should...

    - Use "PChar" instead of "String" (String is a delphi type, C++ CLI doesn't
    known anything about Delphi strings)
    - Use "stdcall" calling convention (By default Delphi use its own calling
    convention).

    Regards


    --
    Cholo Lennon
    Bs.As.
    ARG



    Comment

    • Cholo Lennon

      #3
      Re: Calling a Delphi DLL

      Cholo Lennon wrote:
      kelvin.koogan@g ooglemail.com wrote:
      >How can I call a function in a Delphi DLL from C++/CLI?
      >>
      >The Delphi function is declared as follows:
      >>
      >function Func1(IsDsb: Boolean; FirstStr, SecondStr : String): String;
      >>
      >I've tried
      >>
      >[DllImport("mydl l", EntryPoint="Fun c1")]
      >extern "C" char *Func1(int isDsb, char *firstString, char
      >*secondString) ;
      >>
      >Func1(0, "kl;kl;sdfk ", "kdlks;ldfk ");
      >>
      >but I get an access violation. What should I be doing?
      >>
      >What calling convention will the Delphi function use? Does it need to
      >have stdcall added?
      >>
      >
      In Delphi you should...
      >
      - Use "PChar" instead of "String" (String is a delphi type, C++ CLI
      doesn't known anything about Delphi strings)
      - Use "stdcall" calling convention (By default Delphi use its own
      calling convention).
      >
      One more thing...

      If you use "int" for boolean type in C++ CLI and if you're in 32 bits
      architecture, use LongBool in Delphi. Or, in opposition, use bool in C++ CLI if
      you use boolean in delphi.


      Regards


      --
      Cholo Lennon
      Bs.As.
      ARG



      Comment

      • kelvin.koogan@googlemail.com

        #4
        Re: Calling a Delphi DLL

        On 1 Aug, 17:41, "Cholo Lennon" <chololen...@ho tmail.comwrote:
        kelvin.koo...@g ooglemail.com wrote:
        How can I call a function in a Delphi DLL from C++/CLI?
        >
        The Delphi function is declared as follows:
        >
        function Func1(IsDsb: Boolean; FirstStr, SecondStr : String): String;
        >
        I've tried
        >
        [DllImport("mydl l", EntryPoint="Fun c1")]
        extern "C" char *Func1(int isDsb, char *firstString, char
        *secondString);
        >
        Func1(0, "kl;kl;sdfk ", "kdlks;ldfk ");
        >
        but I get an access violation. What should I be doing?
        >
        What calling convention will the Delphi function use? Does it need to
        have stdcall added?
        >
        In Delphi you should...
        >
        - Use "PChar" instead of "String" (String is a delphi type, C++ CLI doesn't
        known anything about Delphi strings)
        - Use "stdcall" calling convention (By default Delphi use its own calling
        convention).
        >
        Regards
        >
        --
        Cholo Lennon
        Bs.As.
        ARG- Hide quoted text -
        >
        - Show quoted text -
        Thanks. I ShortString as good as PChar in this instance?

        KK

        Comment

        • Pavel Minaev

          #5
          Re: Calling a Delphi DLL

          On Aug 1, 11:39 pm, kelvin.koo...@g ooglemail.com wrote:
          On 1 Aug, 17:41, "Cholo Lennon" <chololen...@ho tmail.comwrote:
          - Use "PChar" instead of "String" (String is a delphi type, C++ CLI doesn't
          known anything about Delphi strings)
          Thanks. I ShortString as good as PChar in this instance?
          No. You need to use PChar (which is really just Char^, that is, a
          pointer to characters of the string).

          Comment

          • Cholo Lennon

            #6
            Re: Calling a Delphi DLL

            kelvin.koogan@g ooglemail.com wrote:
            On 1 Aug, 17:41, "Cholo Lennon" <chololen...@ho tmail.comwrote:
            >kelvin.koo...@ googlemail.com wrote:
            >>How can I call a function in a Delphi DLL from C++/CLI?
            >>
            >>The Delphi function is declared as follows:
            >>
            >>function Func1(IsDsb: Boolean; FirstStr, SecondStr : String):
            >>String;
            >>
            >>I've tried
            >>
            >>[DllImport("mydl l", EntryPoint="Fun c1")]
            >>extern "C" char *Func1(int isDsb, char *firstString, char
            >>*secondString );
            >>
            >>Func1(0, "kl;kl;sdfk ", "kdlks;ldfk ");
            >>
            >>but I get an access violation. What should I be doing?
            >>
            >>What calling convention will the Delphi function use? Does it need
            >>to have stdcall added?
            >>
            >In Delphi you should...
            >>
            >- Use "PChar" instead of "String" (String is a delphi type, C++ CLI
            >doesn't known anything about Delphi strings)
            >- Use "stdcall" calling convention (By default Delphi use its own
            >calling convention).
            >>
            >Regards
            >>
            >--
            >Cholo Lennon
            >Bs.As.
            >ARG- Hide quoted text -
            >>
            >- Show quoted text -
            >
            Thanks. I ShortString as good as PChar in this instance?
            No. PChar (pointer to char) is equivalent to char*. ShortString is another
            Delphi type and C++ CLI doesn't know anything about it. BTW ShortString
            internally has (or Is) an array with up 255 chars. In this array the string
            length is stored at the 1st byte and IIRC the string isn't terminated with NULL
            (necessary in every C function that expects a tipical string). This shows the
            incompatiblity between ShortString and the C++ CLI point of view about the array
            of chars.


            --
            Cholo Lennon
            Bs.As.
            ARG



            Comment

            Working...