Board index » delphi » calling DLL's from Delphi

calling DLL's from Delphi

Hi All

I am trying to use a barcode dll with Delphi. I have not been able to
successfully call the routine. I have been advised that there are some
significant differences in function declarations between VB and Delphi.

The original C++ declaration is below, followed by my converted
declaration for VB(4). The VB declaration seems to work fine for VB,
however after many attempts at modifying the declaration for Delphi, I
have not been successful.

The DLL author is not familiar with Delphi, and cannot help me. I would
appreciate any assistance given. Hopefully some kind soul will look at
the function call and think "easy" and rewrite the call in a suitable way
for Delphi users.

(ps. I get an "Error creating process: File not found(2)" error message
when I attempt to run the program with the function call (using my
declaration). I assume this is because of the faulty declaration)

Thank you in advance.

Regards (and a Merry Christmas and a Happy New year to you)

Peter Sanders.

Original C++ declaration

// CREATEPLACEABLEBARCODE
// Create an ALDUS compatible WMF file on disk of the specified barcode..
// This file can then be read back into your program by reading the
// wmf file as a normal picture... Does not require use of OLE unless
// you insert the WMF back into your application as an OLE object if
// your application does not have a native WMF reader.

#ifdef __cplusplus
extern "C" {
#endif    
BOOL FAR PASCAL _export CreatePlaceableBarcode(
               LPSTR fileName,         // Save as a WMF file to this name
                double Wanted_Width,    // In Millimeters
                double Wanted_Height,   // In Millimeters
                HDC hdc,                // set other one to NULL or 0
                LPSTR szData,           // Barcode data string
                LPSTR szText,           // Barcode text string
                int x1,                 // Left x ..set to 0
                int y1,                 // Top y .. set to 0
                int height,             // Set to 110
                long clrFront,          // 32Bit color value for barcode bars
                long clrBack,           // 32Bit color of barcode background
                int iStyle,             // One of BARCODE_XX
                int iBarRatio,          // Ratio 1 to 7 =
                                          (1.75 to 3.0 in .25 increments)
                int iRotation ,         // One of ROTATION_XX
                int iBearerThickness,   // Set to 0
                int cSpacerChar,        // Set to '>'
                LPSTR mFontFace,        // Eg: "Arial", "New Courier"
                int FontFlags,          // Logical _OR_ of FONT_ flags
                int iFontAdjustment,    // value between -30 and 30
                int flag,               // Logical _OR_ of FLAG_ values
                int far *returnWidth,   // Return width in pixels
                int far *returnHeight,  // Returns height in pixels
                int far *barcodeWidth,  // Returns width just of barcode part
                int far *barcodeHeight, // Returns height of just barcode part
                int magic);
#ifdef __cplusplus

Quote
}

#endif

My VB declaration (normally on a single line)

Declare Function CreatePlaceableBarcode Lib "D:\barole2\barcode.dll"
(ByVal FileName As String,
ByVal WantWidth As Double,
ByVal WantHeight As Double,
ByVal hDC As Integer,
ByVal BData As String,
ByVal BText As String,
ByVal x1 As Integer,
ByVal y1 As Integer,
ByVal SetHeight As Integer,
ByVal clrFore As Long,
ByVal clrBack As Long,
ByVal Style As Integer,
ByVal BarRatio As Integer,
ByVal Rotation As Integer,
ByVal BearerThickness As Integer,
ByVal SpacerChar As Integer,
ByVal FontFace As String,
ByVal FontFlags As Integer,
ByVal FontAdjust As Integer,
ByVal Flags As Integer,
ByVal ReturnWidth As String,
ByVal ReturnHeight As String,
ByVal BarcodeWidth As String,
ByVal BarcodeHeight As String,
ByVal Magic As Integer) As Integer

End of VB declaration.

 

Re:calling DLL's from Delphi


In article <4b55g2$3b...@perth.DIALix.oz.au>, psand...@perth.DIALix.oz.aum
says...

Quote

>Hi All
>Regards (and a Merry Christmas and a Happy New year to you)

>Peter Sanders.

>Original C++ declaration

Could you post the Delphi Declare?

Steve Plotkin
Tierra Software Systems

Re:calling DLL's from Delphi


My best guess would be that you are trying to pass character variables as
"var xxx: string"
Try
"xxx: PChar"
i.e. pass a PChar by value. If your variables are "string", look up
StrPCopy.

The fact you're getting that error message suggests your declaration is
pretty much correct already.

Hope this helps,

Catherine.
--
Catherine Rees-Lay                 Cathe...@polyhdrn.demon.co.uk

Polyhedron Software Ltd.        
Programs for Programmers - QA, Compilers, Graphics

************ Visit our Web site on http://www.polyhedron.co.uk/ ************

Re:calling DLL's from Delphi


VB manages strings the same way that C++ does -- NULL terminated. So if
you type PChar for your strings you should have no problems.

--
                        John Sylvestre
                       Montreal, Quebec
                            Canada
******************************************************************
To err is human, but to really foul things up requires a computer.
Anonymous. Quoted in: "Quote Unquote," 22 Feb. 1982, BBC Radio 4
******************************************************************

Other Threads