C++ Syntax to Delphi Syntax

Posted on 2005-04-07
Last Modified: 2012-08-17

Anyone knows the direct correct equivalence of the following C++ declaration:

DWORD CopyToPc( LPCSTR szFileName, const DWORD& dwOno )
DWORD RmConnect( LPCSTR szHostName, WORD wPortNo )

I am trying to access these two functions from a C++ dll using Delphi "external" keyword (Static Integration of the DLL).
I was able to decipher the actual "name" or "index" in the dll using third party "PE Explorer".

function RmConnect( szHostName: LPCSTR; wPortNo: WORD ): LongInt; overload; stdcall;
    external 'RM.dll' name '?RmConnect@CRmTcp@@UAEKPBDG@Z';//index 114;  Is the function parameters correct?

The project was compiled and start-up fine. But when I tried to call the RmConnect activated with the button,
runtime error occurs with the following message:

Debugger Exception Notification:
Project XXX.exe raised exception class EAccessViolation with message 'Access violation at address
77E20315 in module 'user32.dll'. Write of address 00002713'. Process stopped. Use Step or Run to continue.

I used the return data type of DWORD or Longword for RmConnect but still have this
runtime error. Anyone has any idea on this?
Thanks in advance.
Question by:jasongth
    LVL 11

    Expert Comment

    Is this "MEL Standard version" from "MAKINO MILLING MACHINE Co.,Ltd."?
    I currently write a wrapper for it (i guess the version is 3.13).
    The DLL MknEdmRm.dll exports C++ methods so they are not directly callable from Delphi.

    I will write a wrapper DLL in MS VC++ which flattens the API to functions.
    LVL 27

    Expert Comment

    Assuming normal C functions the first is :-

    function CopyToPc(szFileName : PChar; var dwOno : Longword) : Longword;

    where PChar is ^Char. The actual parameter is an array of bytes terminating by a zero byte. Using a Delphi string (FileName : string), you'd pass it as follows :-



    The second function has the same type of parameter, so you'll need to get that right as well.

    Author Comment

    Hi Robert,

    Just want to know more about this wrapper that you are writing as
    I am trying to use this dll from within my delphi program.

    Yeah, this is the MEL dll.
    LVL 11

    Accepted Solution

    The MknEdmRm.dll (size 98.304 bytes in case you have another version) exports a C++ class and its methods.
    Those are not callable from Delphi because the object implementations of MS VC++ and Delphi are different.

    Thankfully the DLL is easily wrappable. It has a single function GetClassObject which obviously returns the single instance of the C++ object.
    I write a wrapper DLL in VC++ which exports simple functions which internally call the methods of that object, ie flattens the API to C functions.
    It seems that the API is overdefined. It should have been the simple C function API.
    Interestingly CMel.h puts a C++ class on top of that C++ API from MknEdmRm.dll.

    I will also squeeze the support of MAKINO a bit :->
    It should be possible to have them make a simpler DLL.

    I will send you the files as soon as they have been tested (some time next week).
    LVL 11

    Expert Comment

    I have the files ready. Please contact me directly

    Author Comment

    Thanks, robert. Appreciate this effort greatly :)

    Author Comment

    Hi Robert,

    The wrapper dll is working fine in preliminary test such as connection and copy function.
    Thanks, pal :)

    Expert Comment

    Also I've been looking it. Someone can send me ? Or any information about Mel Library.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    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…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 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

    14 Experts available now in Live!

    Get 1:1 Help Now