@rolfk wrote:
In LabVIEW this is simply a pointer sized integer, but that of course does not provide any security for a LabVIEW user to not pass a VkBuffer to a function that wants to see a VkImage! And crash, bumm! 💣
Basically the only way to make such an API LabVIEW safe is to do one of these:
1) wrap everything into LabVIEW classes. Those VkBuffers and VkImages etc. are in fact objects, no matter if the underlaying programming is in C or C++. So you would have to map them to according LabVIEW classes and keep the pointer sized integer a private data element of the class, never to be exposed in any way to the LabVIEW user. That way you can prevent the user from accidentally or willfully mistreat those pointers. These VIs can't be created by the Import Library Wizard, and writing your own variant of such a wizard that creates LabVIEW classes instead would be a major project in its own. Some of the functions the API exposes likely will use complex datatypes as parameter that are difficult to interface from LabVIEW since LabVIEW doesn't really know pointers on the diagram level. Traversing arrays of structures containing pointers in pure LabVIEW code, while not impossible is a true exercise in pointer voodoo far beyond what you would need to do when accessing that same structure in C. So you either end up writing a wrapper function in C anyways or start to play advanced C compiler on the LabVIEW diagram of those VIs.
2) LabVIEW knows a concept of user refnums, but it is not publicly documented. It requires creating a *.rc and according *.rch file that is placed in the <LabVIEW>\resource\objmgr directory and then a restart of LabVIEW. If the *.rc file does not contain any syntax errors, LabVIEW then knows one or more new refnum datatypes that can wrap a pointer sized integer and is type safe as far as LabVIEW is concerned. There are non-public LabVIEW nodes that can wrap the pointer into such a refnum and also deallocate it at the end just like other refnums. The entire thing is highly complex and not for the faint hearted, any errors anywhere in this can lead to very unexpected effects. So I can't recommend its use to anyone.
3) Write a wrapper library in C that exports more LabVIEW friendly APIs. Again you still would have to somehow protect the various object pointers in a way that a casual LabVIEW user is not easily able to mess up. This could be one of the above two options but considering the difficulties with 2) would for anybody but the most diehard nutcases mean to use LabVIEW classes again. 😁
And forget about the Import Library Wizard! It's a nice tool if your API is very simple but simply can't properly import complex APIs. If the API is simple, the effort to create the LabVIEW VIs to call the API functions through Call Library Nodes yourself is negligible anyways. If it is complex, you have to go through each and every function anyways, and carefully review and modify it to be correct and LabVIEW user friendly. This usually amounts to at least as much work as if you had created it all yourself from scratch anyways.
Basically, if you can't create the VIs yourself from scratch, you won't be able to review the wizard created VIs to be correct and use of such VIs in any application simply would be a major liability.