Advice on including 'C' header files in Xojo source

The problem: I am trying to integrate an SDK designed to control a USB camera into a macOS (for now) Xojo Project.

What I have to work with: The camera manufacturer supplies libraries for Win32/64, Linux, Android, and macOS in various DLL’s, SO’s, DYLIB’s, etc., as well as examples in VisualStudio (vb and C#), Java and Python. I also have the straight C header (.h) file describing the libraries - which contain literally hundreds of constants, typedefs, methods, etc.

The question: Does anyone have any advice on how to go about getting the header file into some format that can be used by Xojo? Unfortunately because the Xojo IDE lacks the ability to edit source code in its entirety (see: <> ranked #3 since 2009!), I’m at a loss of how to start.

My (admittedly neanderthal) solution is to put it all into BBEdit and surround everything with the required tags and then see if I can get that to read in the Xojo IDE, but I’m obviously a glutton for punishment (read: idiot), so please tell me there’s an easier way…


I bet others will give you a better answer, but although you say there’s “hundreds” of items in the .h files, you’ll find it’s quite illuminating to “convert” them into Xojo Declares. You learn a lot about what their “engine” is expecting and how it wants you to communicate with it.

A function call can be thought of as a contract. You are putting formatted data on a stack and handing it over to the DLL/DYLIB. Your task is how to format it. Then the DYLIB/DLL understands what you are sending and cooperates. I know that I’m making it sound simple, but after you’ve done a couple of them, it will start seeming simpler to you.

Way back in my VB days, the book that blew me away was Dan Appleman’s Visual Basic Programmer’s Guide to the Win32 API. Basically (pardon the pun) all it was was a primer into converting C Declares into VB ones. (BTW, if they are giving you VB examples, they translate to Xojo very easily.)

Of course, the other route is to make your own DYLIB/DLL and use that as a wrapper to the .h file(s) they give you. If you know C++ and have a touch of VS and XCode experience, it could be cake.

Lastly, perhaps you could post a couple functions from the .h file(s) here and we could get you started.

1 Like

Yes Garth, I should elaborate: I’ll likely start with the VB.NET “class” definition source file (toupcam.vb), but that alone is more than 2400 lines of code! I just need some way to get that imported into Xojo so that I can start making adjustments based on the differences in basic syntax. Or not, it might be easier to edit this entirely outside of the IDE.

You cannot use the .h files directly. As Garth recommends, translate the VB examples to Xojo.

Maybe you can make a DLL function call using a ‘declare’ in Xojo?
[edit]… Mac. I see.

I have examples on how to create a DLL for use in Windows by building in either C++ or C# for Xojo. The DLL’s can then use declares to call the functions. I haven’t created an example for Mac though.

Here are links to the examples:
Create a C# DLL for Xojo

Create a Raw C++ DLL for Xojo

1 Like

Thanks for your replies. Here’s a quick update:

Obviously the c header file wasn’t going to be useful (sorry for the misleading topic title), so I took the .vb class definition and ran that through the VB migration assistant. That took some trickery - it really wants to do an entire project, not just an individual file. The output of that crashed the Xojo IDE and took quite a bit of hand editing just to get it to even load, and the source that it produced was so wonky that I’ve decided to go back to my original approach and do it all - by hand - in BBEdit. Even if I can just get the Constants, Structs, and Enums to load correctly that would save me a ton of work.

I suspect that the VB Migration Assistant is so old that it really can’t handle some of the more modern .NET source convention. You know what would really help? Full module editing :wink:

Take a look at the code generator classes in my Declare Maker utility. The utility itself won’t be helpful, but the classes let you generate a Real Basic project file and are pretty easy to understand. They are edited based on something Norman had put together a while back and might help you with generating projects from C code.