• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

qrencode-win32 / qrcodelib.dll (GNU License)

Started by Roy Chan, November 08, 2011, 08:06:44 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Roy Chan

Dear Sir,

I found another QRCode Encode Library which is under GNU License. But I really don't know how to start and use it.

qrencode-win32
QR Code libraries and utilities for win32
http://code.google.com/p/qrencode-win32/downloads/detail?name=qrcode-win32-3.1.1.zip

QRencode Documentation
http://fukuchi.org/works/qrencode/manual/index.html

/**
* qrencode - QR Code encoder
*
* Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

/** \mainpage
* Libqrencode is a library for encoding data in a QR Code symbol, a kind of 2D
* symbology.
*
* \section encoding Encoding
*
* There are two ways to encode data: <b>encoding a string</b> or
* <b>encoding a structured data</b>.
*
* \subsection encoding-string Encoding a string
* You can encode a string by calling QRcode_encodeString().
* The given string is parsed automatically and encoded. If you want to encode
* data that can be represented as a C string style (NUL terminated), you can
* simply use this way.
*
* If the input data contains Kanji (Shift-JIS) characters and you want to
* encode them as Kanji in QR Code, you should give QR_MODE_KANJI as a hint.
* Otherwise, all of non-alphanumeric characters are encoded as 8 bit data.
* If you want to encode a whole string in 8 bit mode, use
* QRcode_encodeString8bit() instead.
*
* Please note that a C string can not contain NUL character. If your data
* contains NUL, you should chose the second way.
*
* \subsection encoding-input Encoding a structured data
* You can construct a structured input data manually. If the structure of the
* input data is known, you can use this way.
* At first, create a ::QRinput object by QRinput_new(). Then add input data
* to the QRinput object by QRinput_append(). Finally call QRcode_encodeInput()
* to encode the QRinput data.
* You can reuse the QRinput data again to encode it in other symbols with
* different parameters.
*
* \section result Result
* The encoded symbol is resulted as a ::QRcode object. It will contain
* its version number, width of the symbol and an array represents the symbol.
* See ::QRcode for the details. You can free the object by QRcode_free().
*
* Please note that the version of the result may be larger than specified.
* In such cases, the input data would be too large to be encoded in a
* symbol of the specified version.
*
* \section structured Structured append
* Libqrencode can generate "Structured-appended" symbols that enables to split
* a large data set into mulitple QR codes. A QR code reader concatenates
* multiple QR code symbols into a string.
* Just like QRcode_encodeString(), you can use QRcode_encodeStringStructured()
* to generate structured-appended symbols. This functions returns an instance
* of ::QRcode_List. The returned list is a singly-linked list of QRcode: you
* can retrieve each QR code in this way:

* \code
* QRcode_List *qrcodes;
* QRcode_List *entry;
* QRcode *qrcode;
*
* qrcodes = QRcode_encodeStringStructured(...);
* entry = qrcodes;
* while(entry != NULL) {
*     qrcode = entry->code;
*     // do something
*     entry = entry->next;
* }
* QRcode_List_free(entry);
* \endcode
*
* Instead of using auto-parsing functions, you can construct your own
* structured input. At first, instantiate an object of ::QRinput_Struct
* by calling QRinput_Struct_new(). This object can hold multiple ::QRinput,
* and one QR code is generated for a ::QRinput.
* QRinput_Struct_appendInput() appends a ::QRinput to a ::QRinput_Struct
* object. In order to generate structured-appended symbols, it is required to
* embed headers to each symbol. You can use
* QRinput_Struct_insertStructuredAppendHeaders() to insert appropriate
* headers to each symbol. You should call this function just once before
* encoding symbols.
*/

#ifndef __QRENCODE_H__
#define __QRENCODE_H__

#if defined(__cplusplus)
extern "C" {
#endif

/**
* Encoding mode.
*/
typedef enum {
QR_MODE_NUL = -1,  ///< Terminator (NUL character). Internal use only
QR_MODE_NUM = 0,   ///< Numeric mode
QR_MODE_AN,        ///< Alphabet-numeric mode
QR_MODE_8,         ///< 8-bit data mode
QR_MODE_KANJI,     ///< Kanji (shift-jis) mode
QR_MODE_STRUCTURE, ///< Internal use only
} QRencodeMode;

/**
* Level of error correction.
*/
typedef enum {
QR_ECLEVEL_L = 0, ///< lowest
QR_ECLEVEL_M,
QR_ECLEVEL_Q,
QR_ECLEVEL_H      ///< highest
} QRecLevel;

/******************************************************************************
* Input data (qrinput.c)
*****************************************************************************/

/**
* Singly linked list to contain input strings. An instance of this class
* contains its version and error correction level too. It is required to
* set them by QRinput_setVersion() and QRinput_setErrorCorrectionLevel(),
* or use QRinput_new2() to instantiate an object.
*/
typedef struct _QRinput QRinput;

/**
* Instantiate an input data object. The version is set to 0 (auto-select)
* and the error correction level is set to QR_ECLEVEL_L.
* @return an input object (initialized). On error, NULL is returned and errno
*         is set to indicate the error.
* @throw ENOMEM unable to allocate memory.
*/
extern QRinput *QRinput_new(void);

/**
* Instantiate an input data object.
* @param version version number.
* @param level Error correction level.
* @return an input object (initialized). On error, NULL is returned and errno
*         is set to indicate the error.
* @throw ENOMEM unable to allocate memory for input objects.
* @throw EINVAL invalid arguments.
*/
extern QRinput *QRinput_new2(int version, QRecLevel level);

/**
* Append data to an input object.
* The data is copied and appended to the input object.
* @param input input object.
* @param mode encoding mode.
* @param size size of data (byte).
* @param data a pointer to the memory area of the input data.
* @retval 0 success.
* @retval -1 an error occurred and errno is set to indeicate the error.
*            See Execptions for the details.
* @throw ENOMEM unable to allocate memory.
* @throw EINVAL input data is invalid.
*
*/
extern int QRinput_append(QRinput *input, QRencodeMode mode, int size, const unsigned char *data);

/**
* Get current version.
* @param input input object.
* @return current version.
*/
extern int QRinput_getVersion(QRinput *input);

/**
* Set version of the QR-code that is to be encoded.
* @param input input object.
* @param version version number (0 = auto)
* @retval 0 success.
* @retval -1 invalid argument.
*/
extern int QRinput_setVersion(QRinput *input, int version);

/**
* Get current error correction level.
* @param input input object.
* @return Current error correcntion level.
*/
extern QRecLevel QRinput_getErrorCorrectionLevel(QRinput *input);

/**
* Set error correction level of the QR-code that is to be encoded.
* @param input input object.
* @param level Error correction level.
* @retval 0 success.
* @retval -1 invalid argument.
*/
extern int QRinput_setErrorCorrectionLevel(QRinput *input, QRecLevel level);

/**
* Free the input object.
* All of data chunks in the input object are freed too.
* @param input input object.
*/
extern void QRinput_free(QRinput *input);

/**
* Validate the input data.
* @param mode encoding mode.
* @param size size of data (byte).
* @param data a pointer to the memory area of the input data.
* @retval 0 success.
* @retval -1 invalid arguments.
*/
extern int QRinput_check(QRencodeMode mode, int size, const unsigned char *data);

/**
* Set of QRinput for structured symbols.
*/
typedef struct _QRinput_Struct QRinput_Struct;

/**
* Instantiate a set of input data object.
* @return an instance of QRinput_Struct. On error, NULL is returned and errno
*         is set to indicate the error.
* @throw ENOMEM unable to allocate memory.
*/
extern QRinput_Struct *QRinput_Struct_new(void);

/**
* Set parity of structured symbols.
* @param s structured input object.
* @param parity parity of s.
*/
extern void QRinput_Struct_setParity(QRinput_Struct *s, unsigned char parity);

/**
* Append a QRinput object to the set.
* @warning never append the same QRinput object twice or more.
* @param s structured input object.
* @param input an input object.
* @retval >0 number of input objects in the structure.
* @retval -1 an error occurred. See Exceptions for the details.
* @throw ENOMEM unable to allocate memory.
*/
extern int QRinput_Struct_appendInput(QRinput_Struct *s, QRinput *input);

/**
* Free all of QRinput in the set.
* @param s a structured input object.
*/
extern void QRinput_Struct_free(QRinput_Struct *s);

/**
* Split a QRinput to QRinput_Struct. It calculates a parity, set it, then
* insert structured-append headers.
* @param input input object. Version number and error correction level must be
*        set.
* @return a set of input data. On error, NULL is returned, and errno is set
*         to indicate the error. See Exceptions for the details.
* @throw ERANGE input data is too large.
* @throw EINVAL invalid input data.
* @throw ENOMEM unable to allocate memory.
*/
extern QRinput_Struct *QRinput_splitQRinputToStruct(QRinput *input);

/**
* Insert structured-append headers to the input structure. It calculates
* a parity and set it if the parity is not set yet.
* @param s input structure
* @retval 0 success.
* @retval -1 an error occurred and errno is set to indeicate the error.
*            See Execptions for the details.
* @throw EINVAL invalid input object.
* @throw ENOMEM unable to allocate memory.
*/
extern int QRinput_Struct_insertStructuredAppendHeaders(QRinput_Struct *s);

/******************************************************************************
* QRcode output (qrencode.c)
*****************************************************************************/

/**
* QRcode class.
* Symbol data is represented as an array contains width*width uchars.
* Each uchar represents a module (dot). If the less significant bit of
* the uchar is 1, the corresponding module is black. The other bits are
* meaningless for usual applications, but here its specification is described.
*
* <pre>
* MSB 76543210 LSB
*     |||||||`- 1=black/0=white
*     ||||||`-- data and ecc code area
*     |||||`--- format information
*     ||||`---- version information
*     |||`----- timing pattern
*     ||`------ alignment pattern
*     |`------- finder pattern and separator
*     `-------- non-data modules (format, timing, etc.)
* </pre>
*/
typedef struct {
int version;         ///< version of the symbol
int width;           ///< width of the symbol
unsigned char *data; ///< symbol data
} QRcode;

/**
* Singly-linked list of QRcode. Used to represent a structured symbols.
* A list is terminated with NULL.
*/
typedef struct _QRcode_List QRcode_List;

struct _QRcode_List {
QRcode *code;
QRcode_List *next;
};

/**
* Create a symbol from the input data.
* @warning This function is THREAD UNSAFE.
* @param input input data.
* @return an instance of QRcode class. The version of the result QRcode may
*         be larger than the designated version. On error, NULL is returned,
*         and errno is set to indicate the error. See Exceptions for the
*         details.
* @throw EINVAL invalid input object.
* @throw ENOMEM unable to allocate memory for input objects.
*/
extern QRcode *QRcode_encodeInput(QRinput *input);

/**
* Create a symbol from the string. The library automatically parses the input
* string and encodes in a QR Code symbol.
* @warning This function is THREAD UNSAFE.
* @param string input string. It must be NULL terminated.
* @param version version of the symbol. If 0, the library chooses the minimum
*                version for the given input data.
* @param level error correction level.
* @param hint tell the library how non-alphanumerical characters should be
*             encoded. If QR_MODE_KANJI is given, kanji characters will be
*             encoded as Shif-JIS characters. If QR_MODE_8 is given, all of
*             non-alphanumerical characters will be encoded as is. If you want
*             to embed UTF-8 string, choose this.
* @param casesensitive case-sensitive(1) or not(0).
* @return an instance of QRcode class. The version of the result QRcode may
*         be larger than the designated version. On error, NULL is returned,
*         and errno is set to indicate the error. See Exceptions for the
*         details.
* @throw EINVAL invalid input object.
* @throw ENOMEM unable to allocate memory for input objects.
*/
extern QRcode *QRcode_encodeString(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);

/**
* Same to QRcode_encodeString(), but encode whole data in 8-bit mode.
* @warning This function is THREAD UNSAFE.
*/
extern QRcode *QRcode_encodeString8bit(const char *string, int version, QRecLevel level);

/**
* Free the instance of QRcode class.
* @param qrcode an instance of QRcode class.
*/
extern void QRcode_free(QRcode *qrcode);

/**
* Create structured symbols from the input data.
* @warning This function is THREAD UNSAFE.
* @param s
* @return a singly-linked list of QRcode.
*/
extern QRcode_List *QRcode_encodeInputStructured(QRinput_Struct *s);

/**
* Create structured symbols from the string. The library automatically parses
* the input string and encodes in a QR Code symbol.
* @warning This function is THREAD UNSAFE.
* @param string input string. It should be NULL terminated.
* @param version version of the symbol.
* @param level error correction level.
* @param hint tell the library how non-alphanumerical characters should be
*             encoded. If QR_MODE_KANJI is given, kanji characters will be
*             encoded as Shif-JIS characters. If QR_MODE_8 is given, all of
*             non-alphanumerical characters will be encoded as is. If you want
*             to embed UTF-8 string, choose this.
* @param casesensitive case-sensitive(1) or not(0).
* @return a singly-linked list of QRcode. On error, NULL is returned, and
*         errno is set to indicate the error. See Exceptions for the details.
* @throw EINVAL invalid input object.
* @throw ENOMEM unable to allocate memory for input objects.
*/
extern QRcode_List *QRcode_encodeStringStructured(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);

/**
* Same to QRcode_encodeStringStructured(), but encode whole data in 8-bit mode.
* @warning This function is THREAD UNSAFE.
*/
extern QRcode_List *QRcode_encodeString8bitStructured(const char *string, int version, QRecLevel level);

/**
* Return the number of symbols included in a QRcode_List.
* @param qrlist a head entry of a QRcode_List.
* @return number of symbols in the list.
*/
extern int QRcode_List_size(QRcode_List *qrlist);

/**
* Free the QRcode_List.
* @param qrlist a head entry of a QRcode_List.
*/
extern void QRcode_List_free(QRcode_List *qrlist);

#if defined(__cplusplus)
}
#endif

#endif /* __QRENCODE_H__ */



I found the Delphi code from internet. But there is no any sample code to use this library.
http://www.delphimaster.ru/cgi-bin/forum.pl?id=1315555388&n=3&p=1

unit qrencode;

interface

type
QRencodeMode = (
QR_MODE_NUL = -1, ///< Terminator (NUL character). Internal use only
QR_MODE_NUM = 0, ///< Numeric mode
QR_MODE_AN, ///< Alphabet-numeric mode
QR_MODE_8, ///< 8-bit data mode
QR_MODE_KANJI, ///< Kanji (shift-jis) mode
QR_MODE_STRUCTURE
);

QRecLevel = (
QR_ECLEVEL_L = 0, ///< lowest
QR_ECLEVEL_M,
QR_ECLEVEL_Q,
QR_ECLEVEL_H ///< highest
);

BitStream = record
length: LongInt;
data: PChar;
end;

P_QRinput_List = ^_QRinput_List;
_QRinput_List = record
mode: QRencodeMode;
size: LongInt; ///< Size of data chunk (byte).
data: PChar; ///< Data chunk.
bstream: BitStream;
next: P_QRinput_List;
end;

P_QRinput = ^_QRinput;
_QRinput = record
version: LongInt;
level: QRecLevel;
head: P_QRinput_List;
tail: P_QRinput_List;
end;

function QRinput_new: P_QRinput; external 'qrcodelib.dll' name 'QRinput_new';
function QRinput_new2(version: LongInt; level: QRecLevel): P_QRinput; external 'qrcodelib.dll' name 'QRinput_new2';
function QRinput_append(input: P_QRinput; mode: QRencodeMode; size: LongInt; const data: PChar): LongInt; external 'qrcodelib.dll' name 'QRinput_append';
function QRinput_getVersion(input: P_QRinput): LongInt; external 'qrcodelib.dll' name 'QRinput_getVersion';
function QRinput_setVersion(input: P_QRinput; version: LongInt): LongInt; external 'qrcodelib.dll' name 'QRinput_setVersion';
function QRinput_getErrorCorrectionLevel(input: P_QRinput): QRecLevel; external 'qrcodelib.dll' name 'QRinput_getErrorCorrectionLevel';
function QRinput_setErrorCorrectionLevel(input: P_QRinput; level: QRecLevel): LongInt; external 'qrcodelib.dll' name 'QRinput_setErrorCorrectionLevel';
procedure QRinput_free(input: P_QRinput); external 'qrcodelib.dll' name 'QRinput_free';
function QRinput_check(mode: QRencodeMode; size: LongInt; const data: PChar): LongInt; external 'qrcodelib.dll' name 'QRinput_check';

type
P_QRinput_InputList = ^_QRinput_InputList;
_QRinput_InputList = record
input: P_QRinput;
next: P_QRinput_InputList;
end;

P_QRinput_Struct = ^_QRinput_Struct;
_QRinput_Struct = record
size: LongInt; ///< number of structured symbols
parity: LongInt;
head: P_QRinput_InputList;
tail: P_QRinput_InputList;
end;

function QRinput_Struct_new: P_QRinput_Struct; external 'qrcodelib.dll' name 'QRinput_Struct_new';
procedure QRinput_Struct_setParity(s: P_QRinput_Struct; parity: PChar); external 'qrcodelib.dll' name 'QRinput_Struct_setParity';
function QRinput_Struct_appendInput(s: P_QRinput_Struct; input: P_QRinput): LongInt; external 'qrcodelib.dll' name 'QRinput_Struct_appendInput';
procedure QRinput_Struct_free(s: P_QRinput_Struct); external 'qrcodelib.dll' name 'QRinput_Struct_free';
function QRinput_splitQRinputToStruct(input: P_QRinput): P_QRinput_Struct; external 'qrcodelib.dll' name 'QRinput_splitQRinputToStruct';
function QRinput_Struct_insertStructuredAppendHeaders(s: P_QRinput_Struct): LongInt; external 'qrcodelib.dll' name 'QRinput_Struct_insertStructuredAppendHeaders';

type
PQRcode = ^QRcode;
QRcode = record
version: LongInt; ///< version of the symbol
width: LongInt; ///< width of the symbol
data: PChar; ///< symbol data
end;

P_QRcode_List = ^_QRcode_List;
_QRcode_List = record
code: PQRcode;
next: P_QRcode_List;
end;

function QRcode_encodeInput(input: P_QRinput): PQRcode; external 'qrcodelib.dll' name 'QRcode_encodeInput';
function QRcode_encodeString(const str: PChar; version: LongInt; level: QRecLevel; hint: QRencodeMode; casesensitive: LongInt): PQRcode; external 'qrcodelib.dll' name 'QRcode_encodeString';
function QRcode_encodeString8bit(const str: PChar; version: LongInt; level: QRecLevel): PQRcode;external 'qrcodelib.dll' name 'QRcode_encodeString8bit';
procedure QRcode_free(qrcode: PQRcode); external 'qrcodelib.dll' name 'QRcode_free';
function QRcode_encodeInputStructured(s: P_QRinput_Struct): P_QRcode_List; external 'qrcodelib.dll' name 'QRcode_encodeInputStructured';
function QRcode_encodeStringStructured(const str: PChar; version: LongInt; level: QRecLevel; hint: QRencodeMode; casesensitive: LongInt): P_QRcode_List; external 'qrcodelib.dll' name 'QRcode_encodeStringStructured';
function QRcode_encodeString8bitStructured(const str: PChar; version: LongInt; level: QRecLevel): P_QRcode_List; external 'qrcodelib.dll' name 'QRcode_encodeString8bitStructured';
function QRcode_List_size(qrlist: P_QRcode_List): LongInt; external 'qrcodelib.dll' name 'QRcode_List_size';
procedure QRcode_List_free(qrlist: P_QRcode_List); external 'qrcodelib.dll' name 'QRcode_List_free';

implementation

end.





I try to transalate as following.

Enum  QRencodeMode
  QR_MODE_NUL = -1  ///< Terminator (NUL character). Internal use only
  QR_MODE_NUM = 0           ///< Numeric mode
  QR_MODE_AN = 1                    ///< Alphabet-numeric mode
  QR_MODE_8 = 2                       ///< 8-bit data mode
  QR_MODE_KANJI = 3               ///< Kanji (shift-jis) mode
  QR_MODE_STRUCTURE = 4
End Enum

Enum  QRecLevel
  QR_ECLEVEL_L = 0 ///< lowest
  QR_ECLEVEL_M = 1
  QR_ECLEVEL_Q =2
  QR_ECLEVEL_H = 3 ///< highest
End Enum

Type BitStream
  length as Long
  data as Byte
End Type

Type _QRinput_List
  mode as QRencodeMode
  size as Long    ///< Size of data chunk (byte).
  data as Byte            ///< Data chunk.
  bstream as BitStream
  next as _QRinput_List Prt
End Type

Type  _QRinput
  version as Long
  level as QRecLevel
  head as _QRinput_List Ptr
  tail as _QRinput_List Ptr
End Type

Declare function QRinput_new lib "qrcodelib.dll" alias "QRinput_new" as _Qrinput
Declare function QRinput_new2 lib "qrcodelib.dll" alias "QRinput_new2" (byval version as  Long, byval level as QRecLevel) as _QRinput
Declare function QRinput_append lib "qrcodelib.dll' alias "QRinput_append" (byref input as _QRinput, byval mode as QRencodeMode,byval size as Long, byref data as Byte) as Long
Declare function QRinput_getVersion lib "qrcodelib.dll" alias "QRinput_getVersion" (byref input as _QRinput) as Long
Declare function QRinput_setVersion lib "qrcodelib.dll" alias "QRinput_setVersion" (byref input as _QRinput, byval version as Long) as Long
Declare function QRinput_getErrorCorrectionLevel lib "qrcodelib.dll" alias "QRinput_getErrorCorrectionLevel" (byref input as _QRinput) as QRecLevel
Declare function QRinput_setErrorCorrectionLevel lib "qrcodelib.dll" alias "QRinput_setErrorCorrectionLevel" (byref input as_QRinput,byval level as QRecLevel) as Long
Declare sub QRinput_free lib "qrcodelib.dll" alias "QRinput_free" (byref input as _QRinput)
Declare function QRinput_check lib "qrcodelib.dll" alias "QRinput_check" (byval mode as QRencodeMode, byval size as Long, byref data as Byte) as Long

Type  _QRinput_InputList
  input as _QRinput Ptr
  next as _QRinput_InputList Ptr
End Type

Type  _QRinput_Struct
  size as Long     ///< number of structured symbols
  parity as Long
  head as _QRinput_InputList Ptr
  tail as _QRinput_InputList Ptr
End Type

Declare function QRinput_Struct_new  lib "qrcodelib.dll" alias "QRinput_Struct_new" as _QRinput_Struct
Declare sub QRinput_Struct_setParity lib "qrcodelib.dll' alias "QRinput_Struct_setParity" (byref s as _QRinput_Struct, byref parity as Byte)
Declare function QRinput_Struct_appendInput lib "qrcodelib.dll" alias "QRinput_Struct_appendInput" (byref s as  _QRinput_Struct, byref input as _QRinput) as Long
Declare sub QRinput_Struct_free lib "qrcodelib.dll' alias "QRinput_Struct_free" (byref s as _QRinput_Struct)
Declare function QRinput_splitQRinputToStruct lib "qrcodelib.dll" alias "QRinput_splitQRinputToStruct" (byref input as _QRinput) as _QRinput_Struct
Declare function QRinput_Struct_insertStructuredAppendHeaders lib "qrcodelib.dll" alias "QRinput_Struct_insertStructuredAppendHeaders" (byref s as _QRinput_Struct) as Long

Type  QRcode
  version as Long        ///< version of the symbol
  width as Long           ///< width of the symbol
  data as Byte             ///< symbol data
End Type


Type  _QRcode_List
  code as QRcode Ptr
  next as _QRcode_List Ptr
End Type

Delcare function QRcode_encodeInput lib  "qrcodelib.dll" alias "QRcode_encodeInput" (byref input as _QRinput) as QRcode
Delcare function QRcode_encodeString lib "qrcodelib.dll" alias "QRcode_encodeString" (byref str as Byte, byval version as Long, byval level as QRecLevel, byval hint as QRencodeMode, byval casesensitive as Long) as QRcode
Declare function QRcode_encodeString8bit lib "qrcodelib.dll" alias "QRcode_encodeString8bit" (byref str as Byte, byval version as Long, byval level as QRecLevel) as QRcode
Declare sub QRcode_free lib "qrcodelib.dll' alias "QRcode_free" (byref qrcode as QRcode)
Declare function QRcode_encodeInputStructured lib "qrcodelib.dll" alias  "QRcode_encodeInputStructured" (byref s as _QRinput_Struct) as  _QRcode_List
Declare function QRcode_encodeStringStructured lib "qrcodelib.dll" alias "QRcode_encodeStringStructured" (byref str as Byte, byval version as Long,byval level as QRecLevel, byval hint as QRencodeMode, byval casesensitive as Long) as _QRcode_List
Declare function QRcode_encodeString8bitStructured lib "qrcodelib.dll" alias "QRcode_encodeString8bitStructured" (byref str as Byte, byval version as Long, byval level asQRecLevel) as _QRcode_List
Declare function QRcode_List_size lib "qrcodelib.dll" alias "QRcode_List_size" (byref qrlist as _QRcode_List) as Long
Declare sub QRcode_List_free lib "qrcodelib.dll" alias "QRcode_List_free" (byref qrlist as _QRcode_List)
Roy Chan
iniSoft System Technology Limited
Lenovo ThinkPad SL410 4GB Ram,
Windows XP SP3 / PBWin 10 & FireFly 3.5

José Roca


Enum QRencodeMode SINGULAR
  QR_MODE_NUL = -1   ' ///< Terminator (NUL character). Internal use only
  QR_MODE_NUM = 0    ' ///< Numeric mode
  QR_MODE_AN         ' ///< Alphabet-numeric mode
  QR_MODE_8          ' ///< 8-bit data mode
  QR_MODE_KANJI      ' ///< Kanji (shift-jis) mode
  QR_MODE_STRUCTURE
End Enum

Enum QRecLevel SINGULAR
  QR_ECLEVEL_L = 0   ' ///< lowest
  QR_ECLEVEL_M
  QR_ECLEVEL_Q
  QR_ECLEVEL_H       ' ///< highest
End Enum


The use of SINGULAR is optional. If you use it, you will have to use "%" as with a normally defined constant, e.g. %QR_MODE_NUL. If you don't, then you have to use it as, e.g. QRencodeMode.QR_MODE_NUL.

Roy Chan

Roy Chan
iniSoft System Technology Limited
Lenovo ThinkPad SL410 4GB Ram,
Windows XP SP3 / PBWin 10 & FireFly 3.5

José Roca

#3
You can't use an "_" at the beginning with PB, therefore use QRinput instead of _QRinput, etc.

José Roca

/// is not valid in Basic for comments. You have to use "'", e.g.


  QR_MODE_NUL = -1  ' ///< Terminator (NUL character). Internal use only


José Roca

Quote
Declare function QRinput_new lib "qrcodelib.dll" alias "QRinput_new" as _Qrinput

That C library doesn't use stdcall, therefore you have to add CDECL. Also, you use an structure as the return type of a function.


Declare function QRinput_new CDECL lib "qrcodelib.dll" alias "QRinput_new" as DWORD


Roy Chan

#6
According to your indication. I can compiled the project without any error.


Enum  QRencodeMode
  QR_MODE_NUL = -1  '< Terminator (NUL character). Internal use only
  QR_MODE_NUM = 0           '< Numeric mode
  QR_MODE_AN = 1              '< Alphabet-numeric mode
  QR_MODE_8 = 2                 '< 8-bit data mode
  QR_MODE_KANJI = 3         '< Kanji (shift-jis) mode
  QR_MODE_STRUCTURE = 4
End Enum

Enum  QRecLevel
  QR_ECLEVEL_L = 0 '< lowest
  QR_ECLEVEL_M = 1
  QR_ECLEVEL_Q = 2
  QR_ECLEVEL_H = 3 '< highest
End Enum

Type BitStream
  length as Long
  data as Byte
End Type

Type QRinput_List
  mode as Integer
  size as Long    '< Size of data chunk (byte)
  data as Byte             '< Data chunk.
  bstream as BitStream
  next as QRinput_List Ptr
End Type

Type QRinput
  version as Long
  level as Integer
  head as QRinput_List Ptr
  tail as QRinput_List Ptr
End Type

Declare function QRinput_new CDECL lib "qrcodelib.dll" alias "QRinput_new" as Dword
Declare function QRinput_new2 CDECL lib "qrcodelib.dll" alias "QRinput_new2" (byval version as  Long, byval level as Integer) as Dword
Declare function QRinput_append CDECL lib "qrcodelib.dll" alias "QRinput_append" (byref input as QRinput, byval mode as Integer,byval size as Long, byref data as Byte) as Long
Declare function QRinput_getVersion CDECL lib "qrcodelib.dll" alias "QRinput_getVersion" (byref input as QRinput) as Long
Declare function QRinput_setVersion CDECL lib "qrcodelib.dll" alias "QRinput_setVersion" (byref input as QRinput, byval version as Long) as Long
Declare function QRinput_getErrorCorrectionLevel CDECL lib "qrcodelib.dll" alias "QRinput_getErrorCorrectionLevel" (byref input as QRinput) as Integer
Declare function QRinput_setErrorCorrectionLevel CDECL lib "qrcodelib.dll" alias "QRinput_setErrorCorrectionLevel" (byref input as QRinput,byval level as Integer) as Long
Declare sub QRinput_free CDECL lib "qrcodelib.dll" alias "QRinput_free" (byref input as QRinput)
Declare function QRinput_check CDECL lib "qrcodelib.dll" alias "QRinput_check" (byval mode as Integer, byval size as Long, byref data as Byte) as Long

Type  QRinput_InputList
  input as QRinput Ptr
  next as QRinput_InputList Ptr
End Type

Type  QRinput_Struct
  size as Long    '< number of structured symbols
  parity as Long
  head as QRinput_InputList Ptr
  tail as QRinput_InputList Ptr
End Type

Declare function QRinput_Struct_new CDECL lib "qrcodelib.dll" alias "QRinput_Struct_new" as Dword
Declare sub QRinput_Struct_setParity CDECL lib "qrcodelib.dll" alias "QRinput_Struct_setParity" (byref s as QRinput_Struct, byref parity as Byte)
Declare function QRinput_Struct_appendInput CDECL lib "qrcodelib.dll" alias "QRinput_Struct_appendInput" (byref s as  QRinput_Struct, byref input as QRinput) as Long
Declare sub QRinput_Struct_free CDECL lib "qrcodelib.dll" alias "QRinput_Struct_free" (byref s as QRinput_Struct)
Declare function QRinput_splitQRinputToStruct CDECL lib "qrcodelib.dll" alias "QRinput_splitQRinputToStruct" (byref input as QRinput) as Dword
Declare function QRinput_Struct_insertStructuredAppendHeaders CDECL lib "qrcodelib.dll" alias "QRinput_Struct_insertStructuredAppendHeaders" (byref s as QRinput_Struct) as Long

Type QRcode
  version as Long        '< version of the symbol
  width as Long           '< width of the symbol
  data as Byte             '< symbol data
End Type


Type QRcode_List
  code as QRcode Ptr
  next as QRcode_List Ptr
End Type

Declare function QRcode_encodeInput CDECL lib  "qrcodelib.dll" alias "QRcode_encodeInput" (byref input as QRinput) as Dword
Declare function QRcode_encodeString CDECL lib "qrcodelib.dll" alias "QRcode_encodeString" (byref str as Byte, byval version as Long, byval level as Integer, byval hint as Integer, byval casesensitive as Long) as Dword
Declare function QRcode_encodeString8bit CDECL lib "qrcodelib.dll" alias "QRcode_encodeString8bit" (byref str as Byte, byval version as Long, byval level as Integer) as Dword
Declare sub QRcode_free CDECL lib "qrcodelib.dll" alias "QRcode_free" (byref qrcode as QRcode)
Declare function QRcode_encodeInputStructured CDECL lib "qrcodelib.dll" alias  "QRcode_encodeInputStructured" (byref s as QRinput_Struct) as  Dword
Declare function QRcode_encodeStringStructured CDECL lib "qrcodelib.dll" alias "QRcode_encodeStringStructured" (byref str as Byte, byval version as Long,byval level as Integer, byval hint as Integer, byval casesensitive as Long) as Dword
Declare function QRcode_encodeString8bitStructured CDECL lib "qrcodelib.dll" alias "QRcode_encodeString8bitStructured" (byref str as Byte, byval version as Long, byval level as Integer) as Dword
Declare function QRcode_List_size CDECL lib "qrcodelib.dll" alias "QRcode_List_size" (byref qrlist as QRcode_List) as Long
Declare sub QRcode_List_free CDECL lib "qrcodelib.dll" alias "QRcode_List_free" (byref qrlist as QRcode_List)



I don't know how to create a QRCode and put it into a picture control. I found another source about this "QrCodeLib.dll"

PureBasic Forum - Create QRCode (2D-Barcode)
http://www.purebasic.fr/english/viewtopic.php?f=12&t=47938

; by Dige 10/2011
; http://www.purebasic.fr/english/viewtopic.php?f=12&t=47938
; Create 2D Barcodes (QRCode) based on qrencode-win32
; Requires: qrcodelib.lib, qrcodelib.dll
; http://code.google.com/p/qrencode-win32/downloads/list

Structure QRCode
  Version.l
  Width.l
  pSymbolData.l
EndStructure

Enumeration
  #QR_ECLEVEL_L = 0 ; lowest
  #QR_ECLEVEL_M
  #QR_ECLEVEL_Q
  #QR_ECLEVEL_H     ; highest
EndEnumeration

ImportC "..\Lib\qrcodelib.lib"
  QRcode_encodeString8bit(Text.p-ascii, Version.l, QRecLevel.l) As "_QRcode_encodeString8bit"
  QRcode_free(*Qrcode.QRCode) As "_QRcode_free"
EndImport

Procedure CreateQRCode (content.s, ImgID = #PB_Any, EC_Level = #QR_ECLEVEL_L, Size=4 )
  Protected *Qrcode.QRCode, QRImg
 
  *Qrcode = QRcode_encodeString8bit(content, 0, EC_Level)
 
  With *Qrcode
    If *Qrcode = 0 Or \Width = 0
      ProcedureReturn #Null
    Else
      *mem = \pSymbolData
      w    = \Width
    EndIf
  EndWith
 
  QRImg  = CreateImage(ImgID, w, w)
 
  If QRImg
    If ImgID = #PB_Any
      ImgID = QRImg
    EndIf
  EndIf
 
  If StartDrawing(ImageOutput(ImgID))
      ; White Background
      Box (0, 0, ImageWidth(ImgID), ImageHeight(ImgID), #White) 
     
      ; Draw Black Dots
      For y = 0 To w - 1
        For x = 0 To w - 1
          b = PeekB(*mem) & $FF
          If b & 1
            Plot( x, y, #Black)
          EndIf
          *mem + 1
        Next
      Next
     
    StopDrawing()
   
    w * Size
    ResizeImage( ImgID, w, w, #PB_Image_Raw)
  EndIf
 
  QRcode_free(*Qrcode)
 
  ProcedureReturn ImgID
EndProcedure

; Example, how to use it:
CreateImage(0, 200, 200)

OpenWindow(#Null, 0, 0, 450, 400, "2D Barcode Creator", #WS_OVERLAPPEDWINDOW|#PB_Window_ScreenCentered )
TextGadget(#PB_Any, 10, 4, 50, 16, "Text" )
StringGadget(0, 10, 20, 200, 20, "Feel the Pure Power!" )

TextGadget(#PB_Any, 10, 44, 50, 16, "EC_Level" )
TrackBarGadget(1, 10, 60, 100, 20, #QR_ECLEVEL_L, #QR_ECLEVEL_H, #PB_TrackBar_Ticks)

TextGadget(#PB_Any, 110, 44, 50, 16, "Size" )
TrackBarGadget(2, 110, 60, 100, 20, 1, 10, #PB_TrackBar_Ticks)

ImageGadget (3, 10, 90, 430, 550, ImageID(0), #PB_Image_Border)

Repeat
 
  Event = WaitWindowEvent()
 
  If Event = #PB_Event_Gadget
    Select EventGadget()
      Case 0, 1, 2
        ImgID = CreateQRCode(GetGadgetText(0), #Null, GetGadgetState(1), GetGadgetState(2))
        If IsImage(ImgID)
          SetGadgetState(3, ImageID(ImgID))
        EndIf
    EndSelect
  EndIf

Until Event = #PB_Event_CloseWindow





Roy Chan
iniSoft System Technology Limited
Lenovo ThinkPad SL410 4GB Ram,
Windows XP SP3 / PBWin 10 & FireFly 3.5

Roy Chan

I try to translate the  following code. 


  *Qrcode = QRcode_encodeString8bit(content, 0, EC_Level)
 
  With *Qrcode
    If *Qrcode = 0 Or \Width = 0
      ProcedureReturn #Null
    Else
      *mem = \pSymbolData
      w    = \Width
    EndIf
  EndWith


Function FRMMAIN_CreateQrCode   As Long
  Local tmpQrCode As qrcode Ptr
  Local tmpString As String
  Dim  tmpData (0 To 100) As Byte   
  Local mem As Byte Ptr
  Local w As Long

  tmpString="ABCDEFGHIJKLMN"
  FF_MemCopy(StrPtr(tmpString),VarPtr(tmpdata(0)) , Len(tmpString))   

  tmpqrcode=qrcode_encodestring8bit(tmpdata(0),0,0)
  '  ztrace Str$(tmpqrcode)
 
  If tmpqrcode =0 Or @tmpqrcode.Width =0 Then
    Function = %false
     
  Else
    mem=VarPtr(tmpqrcode.Data(0))
    w=@tmpqrcode.Width 
'    ztrace Str$(w)
   
  End If


  Function = %True

End Function


The error appear at    "mem=VarPtr(tmpqrcode.Data(0))". If I remark this line then every thing is OK. The value of  "w" is 21. I think the qrcode generate correctly.
Roy Chan
iniSoft System Technology Limited
Lenovo ThinkPad SL410 4GB Ram,
Windows XP SP3 / PBWin 10 & FireFly 3.5

José Roca

This is wrong:


Type  QRcode
  version as Long        ///< version of the symbol
  width as Long           ///< width of the symbol
  data as Byte             ///< symbol data
End Type


should be:


Type  QRcode
  version as Long        ///< version of the symbol
  width as Long           ///< width of the symbol
  data as Byte Ptr             ///< symbol data
End Type




Roy Chan

I have checked that there is something inside the qrcode.data. But when I tried to draw the qrcode to bitmap. There is nothing shown in the picture control. I want to draw the qrcode into the bitmap first. And then I want to resize it to a bigger size and show it in the picture control.  What's wrong with my code ?



Function FRMMAIN_CreateQrCode   As Long
  Local tmpQrCode As qrcode Ptr
  Local tmpString As String
  Local mem As Dword
  Local tmpLength As Integer 
  Local tmpWidth As Long
  Local lngY As Long
  Local lngX As Long
  Local tmpByte As Integer
  Local tmpBit As Integer
  Local tmpBitMap As Dword
  Dim tmpData () As Byte 
       
       
  tmpString="ABCDEFGHIJKLMN"
  tmplength=Len(tmpstring)
 
  ReDim tmpdata(tmplength)
   
  FF_MemCopy(StrPtr(tmpString),VarPtr(tmpdata(0)) , Len(tmpString))   
  'ztrace Str$( @tmpqrcode.version)

  tmpqrcode=qrcode_encodestring8bit(tmpdata(0),0,2)
  '  ztrace Str$(tmpqrcode)
 
  If tmpqrcode =0 Or @tmpqrcode.Width =0 Then
    Function = %false
     
  Else
    mem=@tmpqrcode.Data
    tmpwidth=@tmpqrcode.Width 
  End If
 
  Graphic Bitmap New tmpwidth,tmpwidth To tmpbitmap
  Graphic Attach tmpbitmap,0
  Graphic Box (0,0)- (tmpwidth,tmpwidth),0,%White,%White
       
  ' Draw Black Dots
  For lngy = 0 To tmpwidth - 1
    For lngx = 0 To tmpwidth - 1
      tmpbyte=CInt(Peek(mem))
      tmpbit=Bit(tmpbyte,0)
      ztrace Str$(tmpbyte)
      If tmpbit=1 Then
        Graphic Set Pixel (lngx, lngy),%Black
        'ztrace "1" & $Nul
      Else
        'ztrace "0" & $Nul
      End If
     
     Incr mem
    Next
  Next

  Graphic ReDraw
 
  SendMessage (HWND_FRMMAIN_PICTURE1, %STM_SETIMAGE, %IMAGE_BITMAP, tmpbitmap)       
  FF_Control_Redraw HWND_FRMMAIN_PICTURE1
 
           
  Function = %True

End Function


Roy Chan
iniSoft System Technology Limited
Lenovo ThinkPad SL410 4GB Ram,
Windows XP SP3 / PBWin 10 & FireFly 3.5

José Roca

You're mixing DDT and SDK. They aren't compatible.

Roy Chan

Dear Jose,

Thank you very much.

I add a customcontrol to replace the picture control and add the following code.


Function FRMMAIN_CUSTOMCONTROL1_INIT ( _
                                     ClassName   As Asciiz, _  ' windows class
                                     Caption     As Asciiz, _  ' window caption
                                     hWndParent  As Dword,  _  ' handle of parent window
                                     ExStyles    As Dword,  _  ' extended window styles
                                     Styles      As Dword,  _  ' standard window styles
                                     nLeft       As Dword,  _  ' left position of control
                                     nTop        As Dword,  _  ' top position of control
                                     nWidth      As Dword,  _  ' width of control
                                     nHeight     As Dword   _  ' height of control
                                     ) As Long
   ' If your custom control uses CreateWindowEx then use the template below, otherwise
   ' follow the instructions provided by the Custom Control's author. The Custom Control
   ' INIT function is called during the %WM_CREATE message for the Form on which the
   ' Custom Control is created.
     
   Dialog New Pixels, hWndParent, "", nLeft, nTop, nWidth, nHeight, %WS_CHILD Or %WS_VISIBLE, 0, To hWndGraphicDlg
   Control Add Graphic, hWndGraphicDlg, IDC_FRMMAIN_CUSTOMCONTROL1, "", 0, 0, nWidth, nHeight    ',%ws_border

End Function


I use the following function to create and draw the QRCode into the customcontrol.


Function FRMMAIN_CreateQrCode As Long
  Local tmpQrCode As qrcode Ptr
  Local tmpString As String
  Local mem As Dword
  Local tmpLength As Integer
  Local tmpPixelSize As Integer   
  Local tmpWidth As Long
  Local lngY As Long
  Local lngX As Long
  Local intX As Integer
  Local intY As Integer
  Local tmpByte As Integer
  Local tmpBit As Integer
  Local lngPlotY As Long
  Local lngPlotX As Long
 
  Dim tmpData () As Byte 
 
  tmppixelsize=gudtctx.nPixelSize
 
'------------------------------------                                   
' SPECIFIC CODE FOR A GRAPHIC CONTROL
'------------------------------------                                                                     
                                                                                                   
' Clear the entire selected graphic target
Graphic Clear
             
' Select the graphic target on which future drawing operations will take place
Graphic Attach hWndGraphicDlg, IDC_FRMMAIN_CUSTOMCONTROL1, ReDraw ' Attach GRAPHIC Commands to Graphic Window


  tmpString=FF_RichEdit_GetText( HWND_FRMMAIN_REDTMAIN, %true )
  tmplength=Len(tmpstring)
 
  ReDim tmpdata(tmplength)
 
  FF_MemCopy(StrPtr(tmpString),VarPtr(tmpdata(0)) , Len(tmpString))     
 
  tmpqrcode=qrcode_encodestring8bit(tmpdata(0),gudtctx.nVersion,gudtctx.nCorrectionLevel  )
'  ztrace Str$(tmpqrcode)
 
  If tmpqrcode =0 Or @tmpqrcode.Width =0 Then
    Function = %false
     
  Else
    mem=@tmpqrcode.Data
    tmpwidth=@tmpqrcode.Width 
    'ztrace Str$(mem) & "/" & Str$( @tmpqrcode.version)
  End If
 
  Graphic Set Size tmpwidth*tmppixelsize, tmpwidth *tmppixelsize
  Graphic Box (0,0)- (tmpwidth*tmppixelsize,tmpwidth*tmppixelsize),0,%White,%White
       
  ' Draw Black Dots
  For lngy = 0 To tmpwidth - 1
    For lngx = 0 To tmpwidth - 1
      tmpbyte=CInt(Peek(mem))
      tmpbit=Bit(tmpbyte,0)
      'ztrace Str$(tmpbyte)
      If tmpbit=1 Then
        lngplotx=lngx*tmpPixelSize
        lngploty=lngy*tmpPixelSize
        For inty=0 To tmpPixelSize -1
         For intx=0 To tmpPixelSize -1
            Graphic Set Pixel (lngplotx+intx, lngploty+inty),%Black
         Next
        Next         
      End If
     
      Incr mem
    Next
  Next

   
    ' Update buffered graphical statements, drawing them to the selected graphic target.
    Graphic ReDraw
   
    '------------------------------------                                   
    ' SPECIFIC CODE FOR A GRAPHIC CONTROL
    '------------------------------------                                                                             
    Dialog Show Modeless hWndGraphicDlg       
 
    qrcode_free(@tmpqrcode)

    Function = %True

End Function




But I don't have any equipment to decode the QRCode. I am not sure the contents is correct or not. I still need to add the header for different Data Type.
Roy Chan
iniSoft System Technology Limited
Lenovo ThinkPad SL410 4GB Ram,
Windows XP SP3 / PBWin 10 & FireFly 3.5

Mike Stefanik

I just tested the QR code in your screenshot using my phone, it had no problem decoding it and it was the correct URL.
Mike Stefanik
sockettools.com

Roy Chan

Mike,

Thank you very much. Since I hate all the Smart Phone (IPhone & Android), so I still using a basic features mobile phone.
This software is not for commerical. I produced it only for my learning experiment of PowerBASIC.  After I finished, I will share the soure to everyone.
Roy Chan
iniSoft System Technology Limited
Lenovo ThinkPad SL410 4GB Ram,
Windows XP SP3 / PBWin 10 & FireFly 3.5

Roy Chan

Dear Sir,

I want to copy the Qrcode pattern to the clipboard. But when I used the following code. Nothing happend but also no error was occupied. Do I need to create bitmap first and copy the existing qrcode pattern to bitmap ?


           Clipboard Reset
           Clipboard Set Bitmap hWndGraphicDlg

Roy Chan
iniSoft System Technology Limited
Lenovo ThinkPad SL410 4GB Ram,
Windows XP SP3 / PBWin 10 & FireFly 3.5