Sending Array of Chars to DLL file

I'm converting C++ Header file to Delphi and I faced a problem with sending chars "OUTPUT" to DLL file

C++    :
   void SalCalculate(Date *date,Location *loc,ConfigData *data,char *s):
   char output[3000];                  // Make sure the length is enough. I.e. for year

Delphi :
   procedure SalCalculate (var date: idate;
                         var loc: LOCATION;
                         var data: CONFIGDATA;
                         s: PChar); cdecl stdcall; external SALATD;
  output:   array[0..3000] of Char;

When I run delphi program I got the following error:
EOverflow with message 'Floating point overflow'

Do you have any recommendation to overcome of this problem?
Who is Participating?
shokotahConnect With a Mentor Commented:
In your C++ struct you defined programFlags as int but in Delphi it is string?  It seems to be a hex value so define Delphi as integer and assign it as :

mydata.programFlags := $100;
1. i thinlk ypu need to use or cdecl or stdcall, but not both
2. i think your problem is not linked to char array, but to CONFIGDATA, LOCATION or idate type.

or it could be different alignment in C++ struct and Delphi record
post this type declarations in C and Delphi
overlook2004Author Commented:
Is it CONFIGDATA? I have one doubt about it (PROGRAMFLAGS)

typedef struct {
      int programFlags;                      // Only bit 8-10 are used to indicate the type of calculation
                                                      // Bit 8-10 = 0 Calculate for a day
                                                      // Bit 8-10 = 1 Calculate for a month
                                                      // Bit 8-10 = 2 Calculate for a year
} ConfigData;

data.programFlags=0X100;            // 0X000 for day, 0X100 for month and 0X200 for year calculation

  ConfigData = record
  end {ConfigData};
mydata.programFlags:='0x000';            // 0X000 for day, 0X100 for month and 0X200 for year calculation
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Please the whole C structs.
I bet the problem is in the structure packing.
That means how the elements of the struct/record are packed together (have a look at the difference of record and packed record).
In Delphi you can force a structure packing of 1 byte with packed record. All other packings (2, 4 or 8 byte boundaries) are handled with compiler option.
In C structure packing is not part of the language at all. It is all handled with compiler options or pragmas.

BTW 0x100 = $100
Thanks for the grading overlook2004.

Is the function working now?  
overlook2004Author Commented:

It worked perfectly after changing the type of ProgramFlags to integer instead of string

Thank you  all for quick & greate support

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.