How to call .dylib

Hello everybody,

i downloaded the Lite Version of Debenu Quick PDF Library. It includes a .dylib File. How can i call that from Xojo? Any Tutorials?

Greetings & Thank you

Take a look at the Declare statement.

…there is nothing about external Dylibs. They only wrote about Standard Cocoa and Carbon-Libs :confused:

Look at the documentation about the Declare statement. The “Lib” section is where you say “here is the dylib path” and point to the dylib. It’s just like a DLL.

I do agree the documentation (now) completely avoids the topic of paths and calling your own DLL/dylibs. They even avoid talk of the custom @executable_path macro where you start defining a relative path.

What is the difference with CONST and Declare?

CONST dylibLocation = “@executable_path/libDebenuPDFLibrary64CPLiteDylib1115.dylib”

I thought it because I found this Norman Pallardy’s doc: http://www.realsoftwareblog.com/2011/12/how-to-create-dylib-on-mac-os-x-and.html that talk about Import Dylib into Xojo.

After declare it the path of the Dylib.

Then became to declare the Functions inside of the Dylib,like this:

I found this INT values inside of the “h” file of the Objective C:

I Opened the DebenuPDFLibraryCPLiteDylibObjC1115.h with Xcode, in order to find the INT values for Declare that in Xojo, and that Is what I found:

(int)AddImageFromFile:(NSString *)FileName :(int)Options;
(int)AddLinkToWeb:(double)Left :(double)Top :(double)Width :(double)Height :(NSString *)Link :(int)Options;
(int)AddStandardFont:(int)StandardFontID;
(int)DeletePages:(int)StartPage :(int)PageCount;
(int)DocumentCount;
(int)DrawHTMLText:(double)Left :(double)Top :(double)Width :(NSString *)HTMLText;
(NSString *)DrawHTMLTextBox:(double)Left :(double)Top :(double)Width :(double)Height :(NSString *)HTMLText;
(int)DrawImage:(double)Left :(double)Top :(double)Width :(double)Height;
(int)DrawQRCode:(double)Left :(double)Top :(double)SymbolSize :(NSString *)Text :(int)EncodeOptions :(int)DrawOptions;
(int)DrawText:(double)XPos :(double)YPos :(NSString *)Text;
(int)DrawTextBox:(double)Left :(double)Top :(double)Width :(double)Height :(NSString *)Text :(int)Options;
(int)ExtractPages:(int)StartPage :(int)PageCount;
(int)FindImages;
(int)GetImageListCount:(int)ImageListID;
(NSString *)GetImageListItemFormatDesc:(int)ImageListID :(int)ImageIndex :(int)Options;
(NSString *)GetInformation:(int)Key;
(double)GetPageBox:(int)BoxType :(int)Dimension;
(int)GetPageImageList:(int)Options;
(int)HasFontResources;
(int)ImageCount;
(int)ImageHeight;
(int)ImageWidth;
(int)IsLinearized;
(int)LastErrorCode;
(int)LoadFromFile:(NSString *)FileName :(NSString *)Password;
(int)MergeDocument:(int)DocumentID;
(int)NewDocument;
(int)NewPage;
(int)NormalizePage:(int)NormalizeOptions;
(int)PageCount;
(int)PageHasFontResources:(int)PageNumber;
(double)PageHeight;
(int)PageRotation;
(double)PageWidth;
(int)RemoveDocument:(int)DocumentID;
(int)RotatePage:(int)PageRotation;
(int)SaveToFile:(NSString *)FileName;
(int)SecurityInfo:(int)SecurityItem;
(int)SelectDocument:(int)DocumentID;
(int)SelectFont:(int)FontID;
(int)SelectImage:(int)ImageID;
(int)SelectPage:(int)PageNumber;
(int)SelectedDocument;
(int)SetBaseURL:(NSString *)NewBaseURL;
(int)SetInformation:(int)Key :(NSString *)NewValue;
(int)SetMeasurementUnits:(int)MeasurementUnits;
(int)SetOrigin:(int)Origin;
(int)SetPageBox:(int)BoxType :(double)Left :(double)Top :(double)Width :(double)Height;
(int)SetPageDimensions:(double)NewPageWidth :(double)NewPageHeight;
(int)SetPageLayout:(int)NewPageLayout;
(int)SetPageMode:(int)NewPageMode;
(int)SetPageSize:(NSString *)PaperName;
(int)SetTextAlign:(int)TextAlign;
(int)SetTextColor:(double)Red :(double)Green :(double)Blue;
(int)SetTextSize:(double)TextSize;
(int)SetTextUnderline:(int)Underline;

So, for Example If I want to Declare,one of that functions, Is it wright to do this?:

Example I’ll gonna try with this: - (int)DrawText:(double)XPos :(double)YPos :(NSString *)Text;

Declare Function DrawText lib dylibLocation (x as double, y as double, text as String)

Or that way: Declare Function DrawText lib dylibLocation (x as double, y as double)Text as String ?

But when I do it, It said me this error: This Declare Function statement is missing its return type

What Am I doing wrong?

If you say declare FUNCTION then the declare must have a return type. If you don’t want a return type use declare SUB. Also, you can’t use String in a declare. Since it is an NSString you should use a CFStringRef in the declare. Additionally these are probably the selectors on an object so you need to include the implicit self parameter in your declare as well as include the full selector in the declare. Your declare will be something like:

Declare function drawText Lib dylibLocation selector "DrawText:XPos:YPos:" (obj_id as ptr, x as double, y as double, text as CFStringRef) as integer

Although the functions you posted look malformed or at least not following Obj-C naming conventions so that might not be right.

If I do this, then give this error: External Functions cannot use ordinary strings as parameters. Use Cstring, PString, WString, or CFSStringRef Instead

Does DrawText really return a value? Sounds strange. But in that case, it should probably rather be

Declare Function DrawText lib dylibLocation (x as Double, y as Double, Text as CFStringRef) As Integer

In case Int means something else it would be

Declare Sub DrawText lib dylibLocation (x as Double, y as Double, Text as CFStringRef) 

[quote=199198:@Jason King]If you say declare FUNCTION then the declare must have a return type. If you don’t want a return type use declare SUB. Also, you can’t use String in a declare. Since it is an NSString you should use a CFStringRef in the declare. Additionally these are probably the selectors on an object so you need to include the implicit self parameter in your declare as well as include the full selector in the declare. Your declare will be something like:

Declare function drawText Lib dylibLocation selector "DrawText:XPos:YPos:" (obj_id as ptr, x as double, y as double, text as CFStringRef) as integer

Although the functions you posted look malformed or at least not following Obj-C naming conventions so that might not be right.[/quote]

The Library has A folder Named Objective C, inside of it has two files:

One called: DebenuPDFLibraryCPLiteDylibObjC1115,h
This is where i get the: (int)DrawText:(double)XPos :(double)YPos :(NSString *)Text code

@Ulrich Bogun don’t you need to include the complete selector for this since it is obj-c?

Yeah Its objective C

I must admit I’m not sure. I believe Objective C uses a selector, so probably yes. I think the selector Jason proposed would have to be extended by “Text” too according to the documentation – with a colon if it’s really a function and without if it doesn’t return a value.

This is an example How to use this Library on Windows:

// Create a PDF document with text: “Hello from XOJO”

Dim PDFLibrary As OLEObject
Dim Stf as Integer
Dim PdfFile As String

PdfFile = “C:\TEMP\PDF\HelloFromXojo.pdf”
PDFLibrary = NEW OLEObject(“DebenuPDFLibraryLite1112.PDFLibrary”)
PDFLibrary.DrawText(100, 500, “Hello from XOJO”)

Stf = PDFLibrary.SaveToFile(PdfFile)

//Stf = 0 “The file could not be created”, Stf = 1 “The file was created successfully”
If Stf = 0 Then
MsgBox ("Could not save the PDF file: "+pdfFile)
End If

PDFLibrary = Nil

exception err as oleexception
msgbox err.message

Now I Thought that the DrawText is solved, the PDFLibrary is Solved Am I right or missing something?

The first parameter of the method needs to be an instance of the DebenuPDFLibraryCPLiteDylibObjC1115 class.

When You said this, I understand to declare the Library, like:
CONST dylibLocation = “@executable_path/libDebenuPDFLibrary64CPLiteDylib1115b.dylib”

Is it right?

No, you need to create an instance of DebenuPDFLibraryCPLiteDylibObjC1115 with alloc/init or alloc/initWithDylibFileName:
All the methods like DrawText are instance methods of DebenuPDFLibraryCPLiteDylibObjC1115.

I think the API is strange and violates Objective C method naming conventions:

- (int)DrawText:(double)XPos :(double)YPos :(NSString *)Text;

… would have better been called something like that:

- (int)DrawText:(NSString *)text atX:(double)x atY:(double)y;

But back to translating it to a Xojo declare:

Declare Function DrawText Lib dylibLocation Selector "DrawText:::" _ (DebenuPDFLibraryCPLiteDylibObjC1115_instance As Ptr, _ text As CFStringRef, x As Double, y As Double) As Integer

[quote=199212:@Eli Ott]No, you need to create an instance of DebenuPDFLibraryCPLiteDylibObjC1115 with alloc/init or alloc/initWithDylibFileName:
All the methods like DrawText are instance methods of DebenuPDFLibraryCPLiteDylibObjC1115.[/quote]
How can I do this, I’m a newbie. sorry

This is the code that I have, trying to adapt the Original Code that its planned to use in Windows, for use it for Xojo Mac:

// Create a PDF document with text: “Hello from XOJO”

CONST PDFLibrary = “@executable_path/libDebenuPDFLibrary64CPLiteDylib1115b.dylib”
Dim stf As Integer
Dim pdf As String

Declare Sub DrawText lib PDFLibrary (x as Double, y as Double, Text as CFStringRef)

Yeah in fact the first must be DebenuPDFLibraryCPLiteDylibObjC1115 once instanced I can Invoke the rest of the functions right?