Ran into an unexpected snag today, where the first line compiles â€" and works fine, while the second iteration attempt at generating an EAN with a real life value from a string variable failed to compile with;
Error 480 Parameter Mismatches Definition.
I tried a fixed length string as well, due to the syntax being stated as "
char * Text" â€" no luck there either.
What is it that PB don't like hereg
Quote
RetVal = QuickPDFDrawBarcode( QPDF, 25, 25, 50, 20, "0123456", 1, 0 )
Dim EAN_Value As String
EAN_Value = "0123456"
RetVal = QuickPDFDrawBarcode( QPDF, 25, 25, 50, 20, EAN_Value, 1, 0 )
Reference;
Quote
DLL
int QuickPDFDrawBarcode(int InstanceID, double Left, double Top,double Width, double Height, char * Text, int Barcode, int Options)
Parameters
Left
Horizontal co-ordinate of left edge of the barcode
Top
Vertical co-ordinate of top edge of the barcode
Width
Width of the barcode
Height
Height of the barcode
Text
The barcode data. The barcode can be rotated by appending the following to the barcode data string:
/RC = Rotate clockwise
/RA = Rotate anti-clockwise
/RU = Rotate 180 degrees
Barcode
1 = Code39 (or Code 3 of 9)
2 = EAN-13
3 = Code128
4 = PostNet
5 = Interleaved 2 of 5
Options
Code39:
0 = Default drawing
EAN-13:
0 = Only draw the barcode
1 = Extend the guard bars
2 = Draw the human-readable numbers
3 = Draw the human-readable numbers, with right spacer
Code128:
0 = Default drawing
PostNet:
0 = Default drawing
Interleaved 2 of 5:
0 = Do not add a checksum, no bearer bars
1 = Add a checksum character, no bearer bars
2 = Do not add a checksum, draw bearer bars
3 = Add a checksum character, draw bearer bars
To apply 10% bar width reduction to the barcode, increase the value of the Options parameter by 10
Return values
0 The barcode could not be drawn. Invalid Barcode or Options parameters.
1 The barcode was drawn successfully
When I hit "Post" I almost immediately got the idea to check the declaration in the include file;
AsciiZ!
Quote
Declare Function QuickPDFDrawBarcode Lib "QuickPDFDLL0725.dll" Alias "QuickPDFDrawBarcode" ( _
ByVal iInstanceID As Long, ByVal dLeft As Double, ByVal dTop As Double, _
ByVal dWidth As Double, ByVal dHeight As Double, sText As AsciiZ, _
ByVal iBarcode As Long, ByVal iOptions As Long) As Long
Anyone able to explain why a "direct string value", as used in my prototyping (first line), is accepted?
Because in the first one you are using a string literal, not a variable, and the compiler has to allocate a temporary one to pass a pointer to it, and as it knows, for the type of parameter, that it is an asciiz, this is what it allocates.
Quote
I tried a fixed length string as well, due to the syntax being stated as "char * Text" â€" no luck there either.
What do you bet that if you try BYCOPY EAN_Value with a dynamic string it will work?
I'm not used to PB being helpful at converting between variable types â€" as VB spoiled me with years ago. I did try ByVal as ByCopy didn't come to mind, but you're absolutely right Jose, it works to â€" as it does with using a ("oversized") StringZ variable.
Thanks for your info on what PB does when using string literals.
Quote
I did try ByVal [...]
What do you bet that if you try BYVAL
STRPTR(EAN_Value) with a dynamic string it will also work?
Quote
[...] as VB spoiled me with years ago.
A language that uses BYVAL STRING to pass an ASCIIZ string by REFERENCE (two lies in two words) is certainly not the best tool to learn parameter passing conventions :)
I was just so preoccupied with the thought of the function being made for passing on a regular string to it. Mix that with some lack of hardcore knowledge from being spoiled by VB, and some time pressure ...
Actually trying pointers did cross my mind in the messy thought process I had that day. Anyway, I'm glad to see there are optional ways of reaching "Rome" when the roads are bumpy. 8o)