Label Printing Fails after creating build

I am facing a strange issue.
I have created a small Desktop application for Zebra label printing.
It works fine until i create build of it, once i create a build it fails to print from build and also fails next time when running from code.

I am getting OutofBound exception in StartDoc method at line -
mb.ptr(8)= mb3

I am not getting what happen when i create build.

Has anyone faced similar kind of error ?

  1. Do you have any #If DebugBuild Then code in your project?
  2. What does your code in StartDoc look like?

No don’t have #If DebugBuild

I think its related to 32 bit and 64 bit version, i need 64 bit build

here is my StartDoc code-

dim job as integer

dim mb as new memoryblock(12)
dim mb1 as MemoryBlock
dim mb2 as MemoryBlock
dim mb3 as MemoryBlock

mb1= new MemoryBlock(jobname.len+1)
mb2= new MemoryBlock(4)
mb3= new MemoryBlock(4)

mb1.CString(0)= jobname
mb2.Cstring(0)= “”
mb3.CString(0)= “RAW”
mb.ptr(0)= mb1
mb.ptr(4)= mb2
mb.ptr(8)= mb3

declare function StartDocPrinterA lib “winspool.drv” (phandle as integer, level as integer, _
d as ptr) as integer

job= StartDocPrinterA(handle, 1, mb)

return job

  1. Are you changing from 32 to 64 bit between your run in the ide vs build ?
  2. What version of Xojo are you using?

A Ptr is 4 bytes for 32-bit apps and 8 bytes for 64-bit apps.
So on 64 bit, mb.ptr(8) is trying to write 4 bytes beyond the size of the memoryblock

Build for 32bit?

Yes, i am trying to change from 32 bit to 64 bit

and i just tried for 32 bit, its working fine.

Hello Jeff,
32 bit build is working,
Can you please tell me what i need to change so that it will work for 64 bit also ?

Can you please tell me what i need to change so that it will work for 64 bit also ?


But I can say: ship a 32 bit app. Why does it need to be 64bit?

This should work in 32 and 64:

Dim job As Integer

Dim mb As New MemoryBlock(COM.SIZEOF_PTR * 3)
Dim mb1 As MemoryBlock
Dim mb2 As MemoryBlock
Dim mb3 As MemoryBlock
mb1 = New MemoryBlock(jobname.len + 1)
mb2 = New MemoryBlock(1)
mb3 = New MemoryBlock(4)

mb1.CString(0) = jobname
mb2.CString(0) = ""
mb3.CString(0) = "RAW"
mb.Ptr(COM.SIZEOF_PTR * 0) = mb1
mb.Ptr(COM.SIZEOF_PTR * 1) = mb2
mb.Ptr(COM.SIZEOF_PTR * 2) = mb3

Declare Function StartDocPrinterA Lib "winspool.drv" (phandle As Integer, level As Integer, _
d As Ptr) As Integer

job = StartDocPrinterA(handle, 1, mb)

Thanks Julian
This worked for 64 bit.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.