[Pyrex] RE: Pyrex Header Wrapping
Grant McDonald
gmcdonald at infocomp.com
Fri Sep 10 01:43:13 CEST 2004
I believe it is because you put the colon after the variable declaration. In
python that would indicate the definition of a function or control structure
block:
cdef extern from "ScanAPI.h":
.
.
.
cdef struct tagSCANDEVINFO:
DWORD StructSize
SCANNER_TYPE ScannerType
unsigned int fHardwareTrigger :1 <-- this is the problem
The rest of the list can tell me if I'm wrong but Pyrex doesn't require you
to be this specific. Merely define them without the :1 (is this bitwise
alignment?) and Pyrex will pick up the correct definition from the real
header. In fact it is even simpler with Pyrex 0.9.3 if you only need to
declare the struct because you need to pass it to a function (i.e. you don't
need to access the data members and don't want the returned values) the
following will be a suitable declaration:
cdef extern from "ScanAPI.h":
.
.
.
cdef struct tagSCANDEVINFO:
pass
If not merely replace you previous definition with the following:
cdef extern from "ScanAPI.h":
.
.
.
cdef struct tagSCANDEVINFO:
DWORD StructSize
SCANNER_TYPE ScannerType
unsigned int fHardwareTrigger
unsigned int fSoftwareTrigger
unsigned int fSoftwareAbortTrigger
unsigned int fGoodReadLight
unsigned int fGoodReadSound
TCHAR SymbolType
Any questions let me know.
Regards,
Grant McDonald
-----Original Message-----
From: Adam McCarthy [mailto:frostbite.adam at gmail.com]
Sent: Friday, 10 September 2004 3:23 AM
To: Grant McDonald
Cc: pyrex at lists.copyleft.no
Subject: Re: Pyrex Header Wrapping
I am currently wrapping the current header to implement a barcode
scanner SDK in a python program. I am currently stuck with the
following error:
ScanAPI.pyx:39:38: C function definition not allowed here
But afaik, I am not defining a function.
This is the original C header:
/***************************************************************************
***********
Copyright (C) 1999 by Socket Communications, All Rights Reserved.
MODULE: ScanAPI.h
PURPOSE: Include file for the Socket Scanner API.
DESCRIPTION: Currently supports only one scanner.
COMMENTS: Initial coding on 9/2/99 by Gary Cuevas
****************************************************************************
************/
#ifdef SCANAPI_EXPORTS
#define SCANAPI_API __declspec(dllexport)
#else
#define SCANAPI_API __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif
// Types of Socket Scanner products
enum SCANNER_TYPE {SCANNER_NONE = 0, // no scanner
SCANNER_CFCARD, //
Socket In-Hand Scan Card
SCANNER_WAND, // a
wand
SCANNER_GUN}; // a
gun
// Types of good-read sounds
enum GRS_TYPE {GRS_NONE = 0, // no good read sound
GRS_MESSAGEBEEP, // play MessageBeep(0) on
good read
GRS_WAVFILE}; // play user-supplied .WAV
file on good read
// Scanner device information structure
typedef struct tagSCANDEVINFO{
DWORD StructSize;
// size of the structure
SCANNER_TYPE ScannerType; // gun,
wand, or integrated card
unsigned int fHardwareTrigger :1; // most likely a gun
unsigned int fSoftwareTrigger :1; // most likely an
integrated card
unsigned int fSoftwareAbortTrigger :1; // most likely an
integrated card
unsigned int fGoodReadLight :1; // most
likely a gun
unsigned int fGoodReadSound :1; // most
likely a gun
TCHAR SymbolType;
// Symbol type code from ISC scanner
} SCANDEVINFO, *LPSCANDEVINFO;
// API return codes
enum SCAN_RESULT {SR_SUCCESS = 0,
SR_INVALID_WMINSERTION,
SR_INVALID_WMREMOVAL,
SR_PLUG_THREAD_FAILURE,
SR_DEVICE_THREAD_FAILURE,
SR_INVALID_SCANNER_HANDLE,
SR_OPEN_FAILURE,
SR_INVALID_WMSCANNERDATA,
SR_NO_DATA,
SR_BUFFER_TOO_SMALL,
SR_SCANNER_NOT_OPEN,
SR_INVALID_SOUND_TYPE,
SR_WAVFILE_NOT_FOUND,
SR_MEMORY_FAILURE,
SR_INVALID_ERR,
SR_TOO_MANY_USERS,
SR_TOO_MANY_ATTEMPTS,
SR_NOT_INITIALIZED,
SR_DEVICE_FAILURE,
SR_INTERNAL_FAILURE,
SR_INVALID_STRUCTURE,
SR_HOTSWAP_ERROR
}; // Load Library call to load the drvr
module failed
// API function prototypes
SCANAPI_API SCAN_RESULT WINAPI ScanInit(HWND hWnd, UINT wmInsertion,
UINT wmRemoval);
SCANAPI_API SCAN_RESULT WINAPI ScanOpenDevice(HANDLE hScanner);
SCANAPI_API SCAN_RESULT WINAPI ScanCloseDevice(HANDLE hScanner);
SCANAPI_API SCAN_RESULT WINAPI ScanGetDevInfo(HANDLE hScanner,
LPSCANDEVINFO lpScanDevInfo);
SCANAPI_API SCAN_RESULT WINAPI ScanRequestDataEvents(HANDLE hScanner,
HWND hWnd, UINT wmScannerData);
SCANAPI_API SCAN_RESULT WINAPI ScanTrigger(HANDLE hScanner);
SCANAPI_API SCAN_RESULT WINAPI ScanAbort(HANDLE hScanner);
SCANAPI_API SCAN_RESULT WINAPI ScanGetData(HANDLE hScanner, TCHAR *
lpBuff, LPINT BufSize);
SCANAPI_API SCAN_RESULT WINAPI ScanSetGoodReadSound(HANDLE hScanner,
GRS_TYPE Sound, LPCTSTR lpWavFile);
SCANAPI_API SCAN_RESULT WINAPI ScanDeinit(void);
SCANAPI_API SCAN_RESULT WINAPI ScanErrToText(SCAN_RESULT Err, LPTSTR
lpBuff, LPINT BufSize);
#ifdef __cplusplus
}
#endif
============================================================
And this is my wrapper:
cdef extern from "stdafx.h":
ctypedef unsigned long DWORD
ctypedef unsigned short BOOL
ctypedef unsigned short BYTE
ctypedef unsigned short WORD
ctypedef float FLOAT
ctypedef FLOAT *PFLOAT
ctypedef BOOL *PBOOL
ctypedef BOOL *LPBOOL
ctypedef BYTE *PBYTE
ctypedef BYTE *LPBYTE
ctypedef int *PINT
ctypedef int *LPINT
ctypedef WORD *PWORD
ctypedef WORD *LPWORD
ctypedef long *LPLONG
ctypedef DWORD *PDWORD
ctypedef DWORD *LPDWORD
ctypedef void *LPVOID
ctypedef int INT
ctypedef unsigned int UINT
ctypedef unsigned int *PUINT
cdef extern from "ScanAPI.h":
cdef enum SCANNER_TYPE:
SCANNER_NONE = 0 # no scanner
SCANNER_CFCARD # Socket In-Hand Scan Card
SCANNER_WAND # a wand
SCANNER_GUN # a gun
cdef enum GRS_TYPE:
GRS_NONE = 0 # no good read sound
GRS_MESSAGEBEEP # play MessageBeep(0) on good read
GRS_WAVFILE # play user-supplied .WAV on good
read
cdef struct tagSCANDEVINFO:
DWORD StructSize # size of
the structure
SCANNER_TYPE ScannerType # gun, wand,
or integrated card
unsigned int fHardwareTrigger :1 # most likely a gun
unsigned int fSoftwareTrigger :1 # most likely an
integrated card
unsigned int fSoftwareAbortTrigger :1 # most likely an integrated
card
unsigned int fGoodReadLight :1 # most likely a gun
unsigned int fGoodReadSound :1 # most likely a gun
TCHAR SymbolType # Symbol
type code from ISC scanner
ctypedef tagSCANDEVINFO SCANDEFINFO
ctypedef tagSCANDEVINFO *LPSCANDEVINFO
cdef enum SCAN_RESULT:
SR_INVALID_WMINSERTION
SR_INVALID_WMREMOVAL
SR_PLUG_THREAD_FAILURE
SR_DEVICE_THREAD_FAILURE
SR_INVALID_SCANNER_HANDLE
SR_OPEN_FAILURE
SR_INVALID_WMSCANNERDATA
SR_NO_DATA
SR_BUFFER_TOO_SMALL
SR_SCANNER_NOT_OPEN
SR_INVALID_SOUND_TYPE
SR_WAVFILE_NOT_FOUND
SR_MEMORY_FAILURE
SR_INVALID_ERR
SR_TOO_MANY_USERS
SR_TOO_MANY_ATTEMPTS
SR_NOT_INITIALIZED
SR_DEVICE_FAILURE
SR_INTERNAL_FAILURE
SR_INVALID_STRUCTURE
SR_HOTSWAP_ERROR
SCAN_RESULT WINAPI ScanInit(HWND hWnd, UINT wmInsertion, UINT wmRemoval)
SCAN_RESULT WINAPI ScanOpenDevice(HANDLE hScanner)
SCAN_RESULT WINAPI ScanCloseDevice(HANDLE hScanner)
SCAN_RESULT WINAPI ScanGetDevInfo(HANDLE hScanner, LPSCANDEVINFO
lpScanDevInfo)
SCAN_RESULT WINAPI ScanRequestDataEvents(HANDLE hScanner, HWND
hWnd, UINT wmScannerData)
SCAN_RESULT WINAPI ScanTrigger(HANDLE hScanner)
SCAN_RESULT WINAPI ScanAbort(HANDLE hScanner)
SCAN_RESULT WINAPI ScanGetData(HANDLE hScanner, TCHAR * lpBuff,
LPINT BufSize)
SCAN_RESULT WINAPI ScanSetGoodReadSound(HANDLE hScanner, GRS_TYPE
Sound, LPCTSTR lpWavFile)
SCAN_RESULT WINAPI ScanDeinit(void)
SCAN_RESULT WINAPI ScanErrToText(SCAN_RESULT Err, LPTSTR lpBuff,
LPINT BufSize)
Thank you very much in advance for your help,
Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.copyleft.no/pipermail/pyrex/attachments/20040910/138d4cbf/attachment.html
More information about the Pyrex
mailing list