Announcement

Collapse
No announcement yet.

Calling a PB DLL from a Delphi EXE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #21
    Originally posted by Paul D. Elliott View Post
    I forgot to move the whole output array out.
    My program was only looking at 1st entry.
    Surely it only needs the pointer to the base of the array?

    Comment


      #22
      Chris,

      Not in this case. The Delphi program created the array. The PB DLL got
      the address of the base of the array. I just forgot to copy the contents
      of the PB array to the Delphi array. I was originally only dealing with one
      variable instead of an array ( just to make sure that the declarations
      worked ).

      I should have said "I forgot to copy the contents of the DLL working array
      to the Delphi output array".

      I have no idea how the Delphi program would act if the PB program
      replaced the array location. In the end, I just tried to follow the code
      that was shown. My contribution was to get the interface to work
      without going BOOM. There are no guarantees that the PB code shown
      in the thread is exactly what is in the real DLL today. But it should
      work.

      Oops. just had another thought.
      What would happen if I replaced the Delphi output array address with the
      PB DLL array address and exited the PB DLL Sub? Would that address
      continue to be valid? Not likely as it is from the stack and who knows
      what other routines will be run before the Delphi program is done with
      the array.

      Or did you know all this and are just trying to teach me something?
      Last edited by Paul D. Elliott; 24 Apr 2012, 06:32 PM.

      Comment


        #23
        Originally posted by Paul D. Elliott View Post
        Ok?
        Wondrous!

        Comment


          #24
          What would happen if I replaced the Delphi output array address with the PB DLL array address and exited the PB DLL Sub? Would that address continue to be valid? Not likely as it is from the stack and who knows what other routines will be run before the Delphi program is done with the array.
          You cannot use the word 'array' interchangeably with either "PowerBASIC" or "Delphi" as the preceding adjective.

          Generically an 'array' is a collection of data elements in contiguous storage accessed by index or subscript. A PB array is the same thing, but internally a PB Array (big A) is held as a 'descriptor' containing a pointer to first element within that contiguous storage. Internally a Delpi Array or array is held as "I don't have a clue." (I don't do Delphi).

          If you want to pass a pointer to the first element of the array, you can work from that. You cannot work between Delphi and PB passing the PB array descriptor.

          The address of the first element of a PB array changes when you REDIM the Array. REDIM also invalidates the original address. LOCAL PowerBASIC array descriptors are stored on the stack but the data elements themselves are always stored in the far heap. STATIC and GLOBAL Array descriptors are stored in memory allocated by the runtime.

          VARPTR (arrayname()) returns the address of the PB Array descriptor.

          VARPTR (arrayname(first element)) returns the address of the first element.

          PB Dynamic string arrays are held as as an array of 32-bit string handles; PB scalar data Arrays are held as the data elements themselves.

          Those are the facts. You may program any way you like as long as you understand them and whatever works best with your "other language" program.

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


            #25
            Originally posted by Paul D. Elliott View Post
            Fredrik,

            Did that answer your question?

            I don't have a version of Delphi later than v7.


            Chris,

            Sorry. I forgot to move the whole output array out.
            My program was only looking at 1st entry.
            Hi everybody

            Sorry for late reply (but better then never )

            I think my code is pretty same as yours Paul (declaration etc.) and I still gets the same error (attached error message in 22 april).

            I wrote the Delphi code in a trial version of IDE XE2 and I made the decision that if I haven't solved the issue it until the trial was over, I should go on with my life and persuade myself that Delphi is a dead language and I shouldn't bother.

            I still bothers me of course but I haven't the time to dig into it more, thanks for all help anyway guys.

            /Fredrik

            Comment


              #26
              Fredrik,

              I don't know what to say.

              I just installed the Delphi XE2 trial. didn't change any defaults ( other than
              setting for 32-bit programs ). running on 32-bit XP sp3.
              no conversion needed.

              only 1 line changed:
              sHeatexType: array [0..100] of AnsiChar; //pAnsiChar;
              changed from [0..100] of Char to the AnsiChar above.

              worked first time after fixing the above line.

              Comment


                #27
                Was my last reply too late to matter?

                I've had very little internet access since the 3rd week of May.

                Comment

                Working...
                X
                😀
                🥰
                🤢
                😎
                😡
                👍
                👎