create declare class from ".framework " file

I want to create class for ".framework " file to make label print easy ". Do I need to create my own class file or there is any tool to get functions and procedure from library.

I got declareMaker thanks for Jason King.

Problem:

Download the documentation of a class as html. This can be done with Option-Return in Safari. Then drag the downloaded file into the Green drop area in the DeclareMaker window. The name of the class should appear in the Listbox to the right of the drop zone. You may keep dropping new files (or a batch of files) to add them to the list. When you are ready to export them as a Xojo project file, click Save and select a location to save the file. You can clear the list of classes which will be generated by clicking on the "C" button in the top right of the window.

What does “documentation of a class as html” mean? and where could I found?

DeclareMaker works in conjunction with Apple’s online developer documentation. It might be a starting point for your own tool, but I think it will not work without modifications for you.

Ok, Correct me, Sometimes declareMaker does not work as per documentation…

I need to create seiko label printer Declare class. I did not find such html documentation on there site.
I have demo example of seiko label printer, But unable to create declare file using datatypes so using “ptr”.
I am new in XOJO, It seems so complicated to me, because I am not able to convert Graphics g to pointer.

It is very appreciated if any reference of code that uses such printing library

http://labelprinters.sii-thermalprinters.com/Downloads/Software/SIISmartLabelPrinterSDK.dmg

It contains SDK and example too. Once your installation completed there is example generated in “HD->Developers -> Example”

Initializing would work like this:

Declare Function SIISLP_Initialize Lib SIISmartibName Selector "SIISLP_Initialize" (callback as ptr, refcon as int32) As int32 Dim result as int32 = SIISLP_Initialize (nil, 0)
A callback function seems to be a bit more complicated. It looks like you would need to build a custom NSObject subclass then; it seems to look for a selector, not a callback block. This is not that trivial if you didn’t do any declares before. Although I guess you could work, at least for the testing period, without events which would become possible (like "printer added"…)

Smartlibname is the path to the framework of course.

You could probably find the first printer by

Dim PrinterRef as Ptr Declare Function SIISLP_FindNext Lib SIISmartibName Selector "SIISLP_FindNext" (Printer as Ptr) As int32 Result = SIISLP_FindNext (PrinterRef)

and cycle through the available printers by repeatedly calling this method, passing PrinterRef again.

Possibly the method to get a printer name would be like

Declare Function SIISLP_GetTextDescription Lib SIISmartibName Selector "SIISLP_GetTextDescription" (Printer as ptr, buffer as ptr, buffersize as UInt32) As int32 dim textblock as new xojo.core.mutablememoryblock(128) result = SIISLP_GetTextDescription (PrinterRef, TextBlock.data, 128)
and then read the result, probably as a CString, from the memoryblock.

EDIT: Not sure if buffersize should be uint or uint32. They talk about size_t, and that might be defined individually.

But this is all hard to tell without a device to test. And it would be worth putting this all into real classes. It’s a very C-like code structure which is a bit cumbersome to handle.

Thank you , I try this and let you know soon

Hi Ulrich,
It is very appreciated what you prepared but still I do not get how to print text and image(barcode) on label printer.
I got your point to create demo example to first initialise and get printer names and all these should be in class that extends NSObject right?
I have problem in what is “callback as ptr” and how to get list of from “Printer as Ptr”
I can use below to get printer. But is it possible to get “Printer as ptr” from “g” below

[code] Dim g As Graphics

g = OpenPrinterDialog[/code]
I need to create method for each declare that you provided above, It is my first time to play with declare. And I have wasted 1 days just for learning it, Still I do not know how to use it with objective C.

[quote=267618:@Ulrich Bogun]Initializing would work like this:

Declare Function SIISLP_Initialize Lib SIISmartibName Selector “SIISLP_Initialize” (callback as ptr, refcon as int32) As int32
Dim result as int32 = SIISLP_Initialize (nil, 0)[/quote]
Either SIISLP_Initialize is a C function or the selector would have to look different. I very much doubt that this library is an Objective C library. So it should be:

Declare Function SIISLP_Initialize Lib SIISmartibName (callback as ptr, refcon as int32) As int32 Dim result as int32 = SIISLP_Initialize (nil, 0)

Callbacks would just be regular shared methods in classes (or functions in modules) with the proper arguments. And not subclasses of NSObject in the Objective C runtime.

Declare Function SIISLP_Initialize Lib SIISmartibName (callback as ptr, refcon as int32) As int32 Dim result as int32 = SIISLP_Initialize (nil, 0)

So I create class that is not subclass of NSObject.
And created method for each above declare that @Ulrich Bogun suggested.
Now it become so complicated to me that which steps first taken,
Can we use below code instead of SIISmartibName

[code] Dim g As Graphics

g = OpenPrinterDialog[/code]

So g is reference to printer.
I just want to print text and barcode on label.

It is confusing to me what is “callback as ptr” and why it is nil reference???

@Eli: I thought so too at first and tried it, but it didn’t work with that library. The same with the callback: Gives an unknown selector if I just try to forward a method address. But it’s of course quite academic: Without a label printer I cannot test further than the init step – which worked with a selector (without colon as one should expect if this code came from Apple) but not without.

@Akshay: Every object in oop is handled via a ptr to the allocated block of RAM the object occupies. So the findNext method if you pass a new Ptr as PrinterRef sets this PrinterRef to the address of the first label printer. If you call the findNext method again, now with PrinterRef being this first printer, it will set PrinterRef to the address of the second printer and so on.

Once you have a valid printer ref, you can cast the different other methods on it that work on such a ptr, like finding the name or print and all. I would recommend using the libraries’ features then, but they are much more low-level than the comfort of the Xojo methods. This is why “wasting one day to learn declares and still not understanding ObjC” sounds a bit funny to me: “I took a whole week of piano lessons and still can’t play Bach’s Toccata” – this is a complex topic, be prepared to spend a few more days for the basics.

If your printer uses the normal printing routines anyway, yes sure, you can just use the Xojo printing methods and probably save days of coding. If you do not need the specialized SDK features: Give it a try! I thought from your initial post use of the library would be mandatory.

But to answer your question: The callback ptr would be a ptr to a method that is called when the library wants to report something back to you asynchronously, without that you asked for it. Like when a new printer was installed. This method takes the printer (as ptr), the status (as Int32, one of the enumeration values) and the int32 identifier you can assign as your own retcon value. And Eli is right: Usually, on an Apple API, this could be a shared method or a block. It looks to me like it wants a ptr to a method installed on an Apple API class instead, because I tried like Eli said first and the errors pointed me to that idea, but I could be wrong. Without a printer myself I cannot verify the code.

Anyway, I pass nil to the init method because currently the callback structure is unsure, and in that case the framework just won’t send notifications by itself which you could use to create events in a Xojo class. See the documentation on the init method: If you pass Nil, no callback will be installed. The second value, 0, is simply the custom RefCon identifier. You can set it to any other integer value.

From the documentation is it a C library or a Objective C library (I don’t want to install the whole thing on my Mac just to be able to read the docs – online there is nothing)?

Found the docs online. So it is a C API as it says on page 4.

[code]Enum SIISLP_ChangeType As Int32
kSIISLPPrinterAdded = 0
kSIISLPPrinterRemoved = 1
End

Sub SIISLP_ChangeCallback(changeCallback As Ptr, changeType As SIISLP_ChangeType, refCon As Int32)
// This is the callback method which will called when a printer is added or removed
// If this method is in a class it needs to be a Shared method

End

Const SIISmartLabelLib = “SIISmartLabelPrinter”
Declare Function SIISLP_Initialize Lib SIISmartLabelLib (changeCallback As Ptr, refCon As Int32) As Int32

Dim status As Int32 = SIISLP_Initialize(AddressOf SIISLP_ChangeCallback, 0)
// If status is 0 then the library is initialized correctly and adding or removing a printer will call SIISLP_ChangeCallback[/code]

His Ulrich Bogun,
I have changed code as per your suggestion,
Printer initialized result := 0
Printer get crashed at

Dim PrinterRef as Ptr Declare Function SIISLP_FindNext Lib SIISmartibName Selector "SIISLP_FindNext" (Printer as Ptr) As int32 Result = SIISLP_FindNext (PrinterRef)

I also tried this too(Removed selector because library is in C )

Declare Function SIISLP_FindNext Lib libraryName (Printer as Ptr) As int32 return SIISLP_FindNext(PrinterRef)

But App still crashed

Please try

Declare Function SIISLP_FindNext Lib SIISmartibName (Byref Printer as Ptr) As int32 Result = SIISLP_FindNext (PrinterRef)

Sets the status for me to -6990 which is probably “no more printer found”.

Byref was missing.
But how does this possible

On xcode SIISLP_FindNext produce -6990 for no more next printer

On XOJO it is still 0

me = -6990

I’m not sure. I have no such printer, so I cannot tell. How many compatible printers are attached to your system? And have you tried to read some of the printer values, like its name, to see if the result is reliable.

Also, you could check for the printerRef before and after the FindeNext call. If it was Nil before and it is not Nil after, it looks like you successfully found a printer.

Why it’s different in Xcode I don’t know. To me the Xojo result looks more promising if you should have a printer attached.

[code]Declare Function SIISLP_FindNext Lib "“SIISmartLabelPrinter” (ByRef printerPtr As Ptr) As Int32

Const kUSBNoDeviceErr = -6990 // No device

Dim printerPtr As Ptr = Nil
Dim result As Int32 = SIISLP_FindNext(printerPtr)
If result = kUSBNoDeviceErr Then
// no printer found
Else
// printerPtr will point to the first printer
// to get the next printer call SIISLP_FindNext with printerPtr
End[/code]