Sending Array of Chars to DLL file

Posted on 2005-05-05
Last Modified: 2010-05-18
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?
Question by:overlook2004
    LVL 6

    Expert Comment

    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

    Author Comment

    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

    Accepted Solution

    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;
    LVL 11

    Expert Comment

    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

    Expert Comment

    Thanks for the grading overlook2004.

    Is the function working now?  

    Author Comment


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

    Thank you  all for quick & greate support


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now