CPP code & Delphi

Hi,

I need to use  some code written in cpp for a Delphi7 project. Never mixed pascal and C source before.

CBulider6 and Delphi7 are close relatives and Cbuilder can use VCL components, but I need the other direction, and I am not familiar with CBuilder at all.

My guess is that maybe there is a way to create a component or package in CBulider and somehow install it to the Delphi IDE. Is this possible? If yes, how?

An ActiveX control could be an other way to do it, but I have never made one before. Escpecially not in CBuilder.

A third attempt could be building a DLL in CBuilder.

What I need is a fast way to make the functionality of the CPP code avaible in Delphi7.

Any help is appreciated. :))

CC
cc042297Asked:
Who is Participating?
 
Russell LibbySoftware Engineer, Advisory Commented:
Download the zip from here:

http://users.adelphia.net/~rllibby/downloads/qrsapi.zip

I created a sample library called QRSApi (.mak project) which exports the desired function. You will find the needed coding changes in the QRSDET2.CPP file, should you wish to implement this in something else (shows how to correctly export the function)

Russell
0
 
MerijnBSr. Software EngineerCommented:
do you actually need vcl or can you just make a normal old fashioned dll?
0
 
ziolkoCommented:
well delphi can generate C like files (projects -> options -> linker -> linker output) so maybe delphi can accept cbuilder output? something like cbuilder's version of dcu then maybe you could use it like any other unit (without source code), but i never done it before so it's just a guess

ziolko.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
cc042297Author Commented:
MerijnB

A DLL would be fine for now. :)

If it is possible to use components written in CPP in Delphi that would be perfect. :))

ziolko

It is really urgent, so I am after a fast working solution.  Thanks for your time anyway.
0
 
MerijnBSr. Software EngineerCommented:
there is tons of info to be found on this topic.
See for example:

http://delphi.about.com/od/objectpascalide/a/dlldelphi.htm (especially http://delphi.about.com/gi/dynamic/offsite.htm?zi=1/XJ&sdn=delphi&cdn=compute&tm=54&f=11&su=p284.8.150.ip_&tt=2&bt=0&bts=0&zu=http%3A//www.drbob42.com/delphi/headconv.htm)

I think it's best to start and get back with questions as you encounter problems.
0
 
cc042297Author Commented:
MerijnB

You are right, normaly I would do much more searching before asking. Yet right now I have zero time for that, so I ask, even if I know it is not a difficult question:

I have never used CBuilder before, havent programed in C for 10 years ... Right now all I need is to tell CBulider to put a function into the DLL's "public" section. I thought "_export" should do the job, yet when I run the the Delphi app, I get the function cannot be located in dll error. So I must be doing something wrong.

Could you help me with this?
0
 
MerijnBSr. Software EngineerCommented:
you could check your DLL with depency walker: http://www.dependencywalker.com/
to find out at what end things are going wrong.
0
 
MerijnBSr. Software EngineerCommented:
iirc, cbuilder didn't use export, that is plain C.
Maybe this can help you: http://www.functionx.com/bcb/libraries/staticdll.htm
0
 
Russell LibbySoftware Engineer, Advisory Commented:
You need to ensure its marked for export, eg:

// This is needed: "extern "C" __declspec(dllexport)"
extern "C" __declspec(dllexport) int YourFunction(double x, bool y)
{

  if (y) {
      return x * 1.0;
  } else {
        return x * -1.0;
  }

}

which will let you call the function using stdcall within Delphi.

Regards,
Russell
0
 
cc042297Author Commented:
Still missing something:

Here is the code:

CBulider

//  OSEA.CPP  ---------------------------------------------------------------------------

#include <vcl.h>
#include <windows.h>
#pragma hdrstop

#pragma argsused

int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
        return 1;
}

//  qrsdet2.cpp  ---------------------------------------------------------------------------

#include <mem.h>
#include <math.h>
#include "qrsdet.h"

// External Prototypes.
...

// Local Prototypes.
...

extern "C" __declspec(dllexport) int QRSDet( int datum, int init )
      {
        ...
      }

//---------------------------------------------------------------------------

Delphi

procedure QRSDet(Ekg_Value, Param: Integer); stdcall ; external 'OSEA.DLL';


The  DLL is  compiled to the dir of the Delphi app. The QRSDet function cannot be loacted in OSEA.DLL .

Any Idea what is wrong?  This Q has turned into a CBuilder Q ...still hoping, that some of you may help. :)  
0
 
MerijnBSr. Software EngineerCommented:
try making it a function in delphi just like in C

function QRSDet(Ekg_Value, Param: Integer): integer; stdcall ; external 'OSEA.DLL';

also check the DLL with the depency viewer I posted before.
0
 
cc042297Author Commented:
MerijnB

I am using it (: thanx :).

It found 2 problems:

Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

DWMAPI.DLL and EFSADU.DLL are the missing ones. I thought these missing files had nothing to do with  the absence of the exported files. The exported functions should be listed in the  top right panel when the dll is selected, yet it is empty.


0
 
cc042297Author Commented:
QRSDet was declared as procedure instead of function. Changed it, but the oiginal problem still remains.

function QRSDet(datum,  Ini: Integer):integer; stdcall ; external 'OSEA.DLL';
0
 
Russell LibbySoftware Engineer, Advisory Commented:
Try the following for the export (worked for me in C++ Builder)

#if defined(__cplusplus)
      #define DLLENTRY extern "C" __declspec(dllexport)
#else
      #define DLLENTRY __declspec(dllexport)
#endif
#define STDENTRY DLLENTRY int WINAPI
#define STDENTRY_(type) DLLENTRY type WINAPI

// External Prototypes.
// ...

// Local Prototypes.
// ...

STDENTRY QRSDet( int datum, int init )
{
  return 0;
}

---

Russell

0
 
cc042297Author Commented:
rllibby

STDENTRY QRSDet( int datum, int init ) ---> STDENTRY int QRSDet( int datum, int init )

I think you have left out the return value type. When I add it, a syntax error occurs when compiling.



0
 
Russell LibbySoftware Engineer, Advisory Commented:
I did not leave out the return value, check the define:

#define STDENTRY DLLENTRY int WINAPI

its defined to return an int.
0
 
cc042297Author Commented:
Oh, Yes! Sorry, should have read much more carefully.

I suggest a possible shortcut, If anyone is willing to try it:

The cpp files can be downloaded here.

http://www.eplimited.com/_vti_bin/shtml.exe/software.htm

Just push submit without filling out the form.

Select  "Beat Detection and Classification Source Code".

The only function I need (QRSDet) is in the  "QRSDET2.CPP" file.

If anyone is willing to try create a DLL project ...

I hope I am not asking too much, I really think this would be the most efficient way to help. :)





 
0
 
cc042297Author Commented:
rllibby

Pasted everything from your comment into my code. Got syntax error here:

STDENTRY QRSDet( int datum, int init )
0
 
cc042297Author Commented:
rllibby

I can't tell you how thankful I am. I truly appreciate your time and effort. :))
0
 
Russell LibbySoftware Engineer, Advisory Commented:
No problem,
Russell
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.