[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

C++ Syntax to Delphi Syntax


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.
1 Solution
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.
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.
jasongthAuthor Commented:
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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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).
I have the files ready. Please contact me directly robert_marquardt@gmx.de
jasongthAuthor Commented:
Thanks, robert. Appreciate this effort greatly :)
jasongthAuthor Commented:
Hi Robert,

The wrapper dll is working fine in preliminary test such as connection and copy function.
Thanks, pal :)
Also I've been looking it. Someone can send me ? Or any information about Mel Library.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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