Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 128131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:35:12+00:00 2026-05-11T05:35:12+00:00

I have a Delphi DLL that I did not write, but need to call

  • 0

I have a Delphi DLL that I did not write, but need to call from a C# ASP.NET 3.5 app. Here is the function definition I got from the developers:

function CreateCode(SerialID : String;      StartDateOfYear, YearOfStartDate, YearOfEndDate, DatePeriod : Word;      CodeType,RecordNumber,StartHour,EndHour : Byte) : PChar;     external 'CreateCodeDLL.dll'; 

And here is my C# code:

[DllImport( 'CreateCodeDLL.dll',      CallingConvention = CallingConvention.StdCall,      CharSet=CharSet.Ansi)] public static extern IntPtr CreateCode( string SerialID,                                         UInt16 StartDateOfYear,                                         UInt16 YearOfStartDate,                                         UInt16 YearOfEndDate,                                         UInt16 DatePeriod,                                         Byte CodeType,                                         Byte RecordNumber,                                         Byte StartHour,                                         Byte EndHour); 

And finally, my call to this method:

//The Inputs  String serialID = '92F00000B4FBE'; UInt16 StartDateOfYear = 20; UInt16 YearOfStartDate = 2009; UInt16 YearOfEndDate = 2009; UInt16 DatePeriod = 7; Byte CodeType = 1; Byte RecordNumber = 0; Byte StartHour = 15; Byte EndHour = 14;              // The DLL call IntPtr codePtr = CodeGenerator.CreateCode(serialID, StartDateOfYear,                  YearOfStartDate, YearOfEndDate, DatePeriod, CodeType,                  RecordNumber, StartHour, EndHour);  // Take the pointer and extract the code in a string String code = Marshal.PtrToStringAnsi(codePtr);   

Every time I re-compile this exact code and run it, it returns a different value. The expected value is a 10-digit code comprised of numbers. The returned value is actually 12 digits.

The last important piece of information is that I have a test .EXE that has a GUI that allows me to test the DLL. Every test using the .EXE returns the same 10-digit number (the expected result).

So, I have to believe that I have declared my call to the DLL incorrectly. Thoughts?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:35:12+00:00Added an answer on May 11, 2026 at 5:35 am

    Delphi uses the so called fastcall calling convention by default. This means that the compiler tries to pass parameters to a function in the CPU registers and only uses the stack if there are more parameters than free registers. For example Delphi uses (EAX, EDX, ECX) for the first three parameters to a function.
    In your C# code you’re actually using the stdcall calling convention, which instructs the compiler to pass parameters via the stack (in reverse order, i.e. last param is pushed first) and to let the callee cleanup the stack.
    In contrast, the cdecl calling used by C/C++ compilers forces the caller to cleanup the stack.
    Just make sure you’re using the same calling convention on both sides. Stdcall is mostly used because it can be used nearly everywhere and is supported by every compiler (Win32 APIs also use this convention).
    Note that fastcall isn’t supported by .NET anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a COM dll written in delphi in our bin folder that call
I need loging all HTTP request (from any application). I have Delphi 7.0. Anybody
I have a Delphi 6 application that sends bitmaps to a DirectShow DLL in
I have a legacy delphi dll. I created a class library that imports the
I have a Delphi DLL that contains the following types: type TStepModeType = (smSingle,
I have a C++ Builder DLL that must link against a Delphi package (BPL),
my delphi 2009 app uses a DLL that performs some activities that may take
I have a Delphi DLL that houses a form which uses a variety of
I have a 3rd party Delphi DLL which I am calling from C++. Unfortunately,
I am trying to call a procedure in a Delphi DLL from C#. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.