Sancarn
Sancarn

Reputation: 2824

Mac native function (ObjC / LibC) to call function with arguments

I maintain a 'modern' VBA library on github stdVBA. The library provides a high level wrapper on top of many low level functions in Windows OS. Mac compatibility is desired and the main obstruction is entry to the ObjC API.

We can get classes using objc_lookUpClass and get pointers to methods with class_getMethodImplementation:

Private Declare Function objc_lookUpClass Lib "/usr/lib/libobjc.A.dylib" (ByVal sClassName As String) As LongPtr
Private Declare Function class_getMethodImplementation Lib "/usr/lib/libobjc.A.dylib" (ByVal klass as LongPtr, ByVal sClassName As String) As LongPtr

Sub main()
  Dim lKlass as LongPtr: lKlass = objc_lookUpClass("NSRegularExpression")
  Dim lMethod as LongPtr: lMethod = class_getMethodImplementation(lKlass, "regularExpressionWithPattern")
  Dim lRegex as LongPtr: lRegex = SOMEHOW_CALL_METHOD(lKlass, "options", 0, "error", AddressOf MyFunction)
End Sub

However we have no method of calling the method pointer we obtain? Unfortunately VBA doesn't supply a method to do so... On windows OS we use DispCallFunc. See example.

Is there an alternative to DispCallFunc defined in libobjc, libc or any other library we have access to natively on Mac?

Upvotes: 2

Views: 86

Answers (0)

Related Questions