Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2012.03.18;
Скачать: CL | DM;

Вниз

Перевод заголовочного файла *.h в подключаемый модуль *.pas   Найти похожие ветки 

 
Василий Жогарев ©   (2011-09-09 12:03) [0]

Уважаемые мастера, прошу Вас оказать содействие в переводе заголовочного файла qrencode.h (C/C++), подключаемой библиотеки qrcodelib.dll, в подключаемый модуль qrencode.pas (Delphi).

http://code.google.com/p/qrencode-win32/downloads/detail?name=qrcode-win32-3.1.1.zip


 
Василий Жогарев ©   (2011-09-09 12:03) [1]

/**
* 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: encoding a string or
* encoding a structured data.
*
* \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.
*/


 
Василий Жогарев ©   (2011-09-09 12:04) [2]

#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;


 
Василий Жогарев ©   (2011-09-09 12:04) [3]

/******************************************************************************
* 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);


 
Василий Жогарев ©   (2011-09-09 12:05) [4]

/******************************************************************************
* 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__ */


 
Василий Жогарев ©   (2011-09-09 12:07) [5]

И так, комментарии можно опустит. Вопрос собственно заключается в правильности перевода структур, перечислений, и вызовов функций.
Сам наверное не справлюсь...

Спасибо.


 
OW ©   (2011-09-09 12:12) [6]

смеётесь?
из всей портянки надо исключить комментарии и взять distinct типов и функций
тогда вероятность ответа будет больше.
( Сейчас она, имхо, близка к 0 :)


 
Василий Жогарев ©   (2011-09-09 12:28) [7]

#ifndef __QRENCODE_H__
#define __QRENCODE_H__

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

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;

typedef enum {
QR_ECLEVEL_L = 0, ///< lowest
QR_ECLEVEL_M,
QR_ECLEVEL_Q,
QR_ECLEVEL_H      ///< highest
} QRecLevel;

typedef struct _QRinput QRinput;

extern QRinput *QRinput_new(void);
extern QRinput *QRinput_new2(int version, QRecLevel level);
extern int QRinput_append(QRinput *input, QRencodeMode mode, int size, const unsigned char *data);
extern int QRinput_getVersion(QRinput *input);
extern int QRinput_setVersion(QRinput *input, int version);
extern QRecLevel QRinput_getErrorCorrectionLevel(QRinput *input);
extern int QRinput_setErrorCorrectionLevel(QRinput *input, QRecLevel level);
extern void QRinput_free(QRinput *input);
extern int QRinput_check(QRencodeMode mode, int size, const unsigned char *data);

typedef struct _QRinput_Struct QRinput_Struct;

extern QRinput_Struct *QRinput_Struct_new(void);
extern void QRinput_Struct_setParity(QRinput_Struct *s, unsigned char parity);
extern int QRinput_Struct_appendInput(QRinput_Struct *s, QRinput *input);
extern void QRinput_Struct_free(QRinput_Struct *s);
extern QRinput_Struct *QRinput_splitQRinputToStruct(QRinput *input);
extern int QRinput_Struct_insertStructuredAppendHeaders(QRinput_Struct *s);

typedef struct {
int version;         ///< version of the symbol
int width;           ///< width of the symbol
unsigned char *data; ///< symbol data
} QRcode;

typedef struct _QRcode_List QRcode_List;

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

extern QRcode *QRcode_encodeInput(QRinput *input);
extern QRcode *QRcode_encodeString(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);
extern QRcode *QRcode_encodeString8bit(const char *string, int version, QRecLevel level);
extern void QRcode_free(QRcode *qrcode);
extern QRcode_List *QRcode_encodeInputStructured(QRinput_Struct *s);
extern QRcode_List *QRcode_encodeStringStructured(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);
extern QRcode_List *QRcode_encodeString8bitStructured(const char *string, int version, QRecLevel level);
extern int QRcode_List_size(QRcode_List *qrlist);
extern void QRcode_List_free(QRcode_List *qrlist);

#if defined(__cplusplus)
}
#endif

#endif /* __QRENCODE_H__ */


А так?... :)


 
Василий Жогарев ©   (2011-09-09 12:32) [8]

Ну допустим начну со структур и перечислений, соответственно структуры в записи structure -> record, перечисления в перечисления.

Но на счет перечислений есть сомнения, может лучше использовать объявленные константы?


 
Василий Жогарев ©   (2011-09-09 12:36) [9]

TQRencodeMode = (
   QR_MODE_NUL = -1,
   QR_MODE_NUM = 0,
   QR_MODE_AN,
   QR_MODE_8,
   QR_MODE_KANJI,
   QR_MODE_STRUCTURE
);


Я правильно понимаю?


 
Василий Жогарев ©   (2011-09-09 12:57) [10]

Прошу модераторов удалить посты под номерами: [1], [2], [3], [4].
Извините за флуд... )


 
Василий Жогарев ©   (2011-09-09 18:24) [11]

Не пойму что за тип и откуда он берется:

typedef struct _QRinput QRinput;

Не совсем понятно, что это? Пустая структура/перечисление или структура/перечисление с одним элементом?

Как это описать ObjectPascal-ем?


 
Василий Жогарев ©   (2011-09-10 11:30) [12]

Другой форум по этому вопросу: http://www.forum.crossplatform.ru/index.php?showtopic=7485&st=0&gopid=52864&#entry52864


 
Кто б сомневался ©   (2011-09-11 04:40) [13]


> прошу Вас оказать содействие в переводе заголовочного файла
> qrencode.h (C/C++), подключаемой библиотеки qrcodelib.dll,
>  в подключаемый модуль qrencode.pas (Delphi).


Прям вынь да положи. Вам деньги заплатят ведь, а не "Уважаемым мастерам".
Я понимаю если что-то конкретное...


 
Василий Жогарев ©   (2011-09-11 08:41) [14]

Поверьте, у нас не заплатят 8)
В таком случае сам разберусь, просто хотел мнения, предложения мастеров услышать, а так-то там нечего переводить на ObjP. Зря так много запостил, единственный вопрос был впринципе в переводе структур, и соответствии типов данных.

Сделаю, выложу, чтобы непосредственно Вы: Кто б сомневался © денег заработали...

Вот какая у вас зарплата на рубли?


 
Василий Жогарев ©   (2011-09-11 14:12) [15]

В общем, перевел структуры и функции.

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.


 
Василий Жогарев ©   (2011-09-11 14:20) [16]

Только вот одно но...

при попытке выполнить код:

procedure TForm1.Button1Click(Sender: TObject);
var
 qrcodes: P_QRcode_List;
 entry: P_QRcode_List;
 qrcode: PQRcode;
begin
 qrcodes := QRcode_encodeStringStructured(PChar("http://delphimaster.ru/"), 0,
   QR_ECLEVEL_H, QR_MODE_AN, 0);
 entry := qrcodes;
 while (entry <> nil) do
 begin
   qrcode := entry.code;
   entry := entry.next;
 end;
 QRcode_List_free(entry);
end;


минуется цикл и идет сразу выгрузка QRcode_List_free(entry); в этот момент происходит ошибка:
First chance exception at $75B5D36F. Exception class EAccessViolation with message "Access violation at address 00000000. Read of address 00000000". Process Project1.exe (5036)

Можно конечно предположить что QRcode_encodeStringStructured ничего не возвращает, поставив условие перед выгрузкой на наличие nil, как бы "обезопасить", происходит другая ошибка: First chance exception at $75B5D36F. Exception class EAccessViolation with message "Access violation at address 00000000. Read of address 00000000". Process Project1.exe (4916)

Что я сделал не так? Уже все возможные варианты перебрал...


 
Василий Жогарев ©   (2011-09-11 14:23) [17]

Вот debug, кажет сюда:

75B5D35C 50               push eax
75B5D35D E88094FFFF       call $75b567e2
75B5D362 83C40C           add esp,$0c
75B5D365 8D45B0           lea eax,[ebp-$50]
75B5D368 50               push eax
75B5D369 FF155C11B575     call dword ptr [$75b5115c]
75B5D36F C9               leave
75B5D370 C21000           ret $0010
75B5D373 8945C0           mov [ebp-$40],eax
75B5D376 EBED             jmp $75b5d365
75B5D378 90               nop


 
Василий Жогарев ©   (2011-09-11 14:25) [18]


> Василий Жогарев ©   (09.09.11 12:57) [10]
> Прошу модераторов удалить посты под номерами: [1], [2],
> [3], [4].
> Извините за флуд... )


 
Anatoly Podgoretsky ©   (2011-09-11 14:42) [19]

> Василий Жогарев  (11.09.2011 14:20:16)  [16]

entry = nil


 
Василий Жогарев ©   (2011-09-11 15:06) [20]


> Anatoly Podgoretsky ©   (11.09.11 14:42) [19]
> > Василий Жогарев  (11.09.2011 14:20:16)  [16]
>
> entry = nil
>
>


Ну это понятно. Пример из модуля гласит:
* \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


Вод собственно и не понятно почему возвращается nil...


 
Василий Жогарев ©   (2011-09-11 15:10) [21]

При переводе у меня вот, что еще вызвало сомнения:

function QRcode_encodeStringStructured(const str: PChar; version: LongInt; level: QRecLevel; hint: QRencodeMode; casesensitive: LongInt): P_QRcode_List; external "qrcodelib.dll" name "QRcode_encodeStringStructured";

/**
* 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);


 
Anatoly Podgoretsky ©   (2011-09-11 15:12) [22]

> Василий Жогарев  (11.09.2011 15:06:20)  [20]

Код QRcode_encodeStringStructured не приведен.


 
Anatoly Podgoretsky ©   (2011-09-11 15:15) [23]

> Anatoly Podgoretsky  (11.09.2011 15:12:22)  [22]

Отдадка тоже не произведена


 
DVM ©   (2011-09-11 15:35) [24]


> Василий Жогарев ©

Везде заменяй PChar на PAnsiChar


 
Василий Жогарев ©   (2011-09-11 16:30) [25]


> DVM ©   (11.09.11 15:35) [24]
> > Василий Жогарев ©Везде заменяй PChar на PAnsiChar


Думаете строго на 8 бит указывает... х.м., все может быть...
Спасибо за подсказку, завтра на работе проверю...


 
DVM ©   (2011-09-11 17:36) [26]


> Василий Жогарев ©   (11.09.11 16:30) [25]

у тебя версия Delhpi то какая?


 
Василий Жогарев ©   (2011-09-12 08:34) [27]


> DVM ©   (11.09.11 17:36) [26]
>
> > Василий Жогарев ©   (11.09.11 16:30) [25]
>
> у тебя версия Delhpi то какая?


Embarcadero® Delphi® 2010 Version 14.0.3593.25826


 
Василий Жогарев ©   (2011-09-12 09:34) [28]


> Везде заменяй PChar на PAnsiChar


Ошибка:
First chance exception at $75DAD36F. Exception class EAccessViolation with message "Access violation at address 00000000. Read of address 00000000". Process Project1.exe (4448)


 
Василий Жогарев ©   (2011-09-12 09:46) [29]


> Anatoly Podgoretsky ©   (11.09.11 15:12) [22]
> > Василий Жогарев  (11.09.2011 15:06:20)  [20]
>
> Код QRcode_encodeStringStructured не приведен.


QRcode_List *QRcode_encodeStringStructured(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive)
{
QRinput *input;
QRcode_List *codes;
int ret;

if(version <= 0) {
 errno = EINVAL;
 return NULL;
}
if(hint != QR_MODE_8 && hint != QR_MODE_KANJI) {
 errno = EINVAL;
 return NULL;
}

input = QRinput_new2(version, level);
if(input == NULL) return NULL;

ret = Split_splitStringToQRinput(string, input, hint, casesensitive);
if(ret < 0) {
 QRinput_free(input);
 return NULL;
}
codes = QRcode_encodeInputToStructured(input);
QRinput_free(input);

return codes;
}


 
Василий Жогарев ©   (2011-09-12 09:57) [30]

QRinput *QRinput_new(void)
{
return QRinput_new2(0, QR_ECLEVEL_L);
}

QRinput *QRinput_new2(int version, QRecLevel level)
{
QRinput *input;

if(version < 0 || version > QRSPEC_VERSION_MAX || level > QR_ECLEVEL_H) {
 errno = EINVAL;
 return NULL;
}

input = (QRinput *)malloc(sizeof(QRinput));
if(input == NULL) return NULL;

input->head = NULL;
input->tail = NULL;
input->version = version;
input->level = level;

return input;
}


 
DVM ©   (2011-09-12 14:04) [31]


> Василий Жогарев ©   (12.09.11 09:34) [28]


> Ошибка:
> First chance exception at $75DAD36F. Exception class EAccessViolation
> with message "Access violation at address 00000000. Read
> of address 00000000". Process Project1.exe (4448)
>
>

Не связано с заменой. С чего ты взял, что в эту dll можно передавать двухбайтовые строки Unicode? Исходя из сишного кода этого нельзя предположить. Там Char - 1 байт. Где то у тебя ошибка. Что это вообще за dll есть какая то документация по ней?


 
DVM ©   (2011-09-12 14:13) [32]


>  Василий Жогарев ©   (12.09.11 09:34) [28]
>

Судя по всему, библиотека работает с разными строками, тип данных задается QR_MODE_XX, но все равно, передавать в функции надо буфер PAnsiString. Как в сишном варианте задекларировано, так и переводи.


 
Василий Жогарев ©   (2011-09-12 19:05) [33]


> Что это вообще за dll есть какая то документация по ней?


http://fukuchi.org/works/qrencode/index.en.html


 
Pat ©   (2011-11-23 16:28) [34]


> Василий Жогарев ©   (12.09.11 19:05) [33]

Как успехи в работе с QRCode? Сейчас ст толкнулся с аналогичной проблемой. Необходимо генерировать qrcode. Пока даже и не знаю с чего начать :)


 
han_malign   (2011-11-23 17:49) [35]

во блин, как же я это такой классный поток бреда от "Мастеров" пропустил...

cdecl(скорее всего) либо stdcall, но уж никак не паскалевский register...


 
Юрий Зотов ©   (2011-11-23 22:35) [36]

Нигде не объявлены соглашения о вызове функций DLL - значит, компилятор использует Паскалевские.

А с чего бы это Сишные DLL вдруг будут использовать Паскалевские соглашения?



Страницы: 1 вся ветка

Текущий архив: 2012.03.18;
Скачать: CL | DM;

Наверх




Память: 0.61 MB
Время: 0.009 c
2-1322678545
Alexey
2011-11-30 22:42
2012.03.18
Двойной клик по заголовку формы


15-1322166427
картман
2011-11-25 00:27
2012.03.18
Service1.exe /install


1-1289241191
DevilDevil
2010-11-08 21:33
2012.03.18
BASM overload


2-1323244056
Дмитрий_
2011-12-07 11:47
2012.03.18
восстановить курсор если найдена запись


15-1322401925
Vyacheslav
2011-11-27 17:52
2012.03.18
Delphi XE2 не работают Break Point