Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 768
  • Last Modified:

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
   SalCalculate(&date,&loc,&data,output);

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

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?
0
overlook2004
Asked:
overlook2004
1 Solution
 
vadim_tiCommented:
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
0
 
overlook2004Author Commented:
Is it CONFIGDATA? I have one doubt about it (PROGRAMFLAGS)

C++
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

Delphi
  ConfigData = record
       ....
    programFlags:string;
  end {ConfigData};
mydata.programFlags:='0x000';            // 0X000 for day, 0X100 for month and 0X200 for year calculation
0
 
shokotahCommented:
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;
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
robert_marquardtCommented:
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
0
 
shokotahCommented:
Thanks for the grading overlook2004.

Is the function working now?  
0
 
overlook2004Author Commented:

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

Thank you  all for quick & greate support


0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now