[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pointers problem


Something is wrong here but I don't know what as I don't understand
that much about pointers.
Sometime it goes to a segmentation error.

' Gambas module file

Library "libqrencode:4"

Public Struct QRcode
iVersion As Integer ' 4 x
iWidth As Integer ' 4 x
pData As Pointer
End Struct

Private Extern QRcode_encodeString(sText As String, iVersion As
Integer, iLevel As Integer, iHint As Integer, iCasesensitive As
Integer) As Pointer
Private Extern QRcode_free(qrcode As Pointer) 'As Integer

' Private Const QR_ECLEVEL_L As Integer = 0
' Private Const QR_ECLEVEL_M As Integer = 1
' Private Const QR_ECLEVEL_Q As Integer = 2
' Private Const QR_ECLEVEL_H As Integer = 3

Public Function GenerateQR(sTextToEncode As String, iLargeur As
Integer) As Image

Dim pQr As Pointer
Dim stQr As New QRcode
Dim img As Image
Dim iX, iY, iInd As Integer
Dim ibByte As Byte
Dim pixelSize As Float
Dim targetSize As Integer = iLargeur

stQr = Null

If IsNull(sTextToEncode) = True Then
 Message.Error(("QR code generation stopped!"))
 Return Null
Endif

' pQr = QRcode_encodeString(sTextToEncode, 0, QR_ECLEVEL_Q, 2, 1)
pQr = QRcode_encodeString(sTextToEncode, 0, 2, 2, 1)

If pQr = Null Then
 Message.Error(("QR code generation failed!"))
 Return Null
Endif

stQr = pQr

' With stQr
' Print .iVersion
' Print .iWidth
' Print .pData
' End With
' Print " "
' Print pqr

pixelSize = targetSize / stQr.iWidth
img = New Image(targetSize, targetSize, Color.White, Image.Standard)

Paint.Begin(img)

For iY = 0 To stQr.iWidth - 1
 For iX = 0 To stQr.iWidth - 1
 ibByte = Byte@(stQr.pData + iInd)

 If (ibByte And 1) Then
 Paint.Brush = Paint.Color(Color.Black)
 Paint.Rectangle(iX * pixelSize, iY * pixelSize,
pixelSize, pixelSize)
 Paint.Fill
 End If

 Inc iInd
 Next
Next

Paint.End

QRcode_free(pQr)
pQr = Null
Return img

End Function

-- 
valaquarus <valaquarus@xxxxxxxxx>

Follow-Ups:
Re: pointers problemLee <t.lee.davidson@xxxxxxxxx>