Passing AddressOf Structure to C API?

So I have created a structure, MyContextStruct in Module1. Its scope is Global, and its definition is:
my_model as Ptr

So this structure will contain one 64-bit pointer.

Now, I want to pass the ADDRESS of that structure to a C-API function, defined as:

MyExternalMethodFoo(myCtxPtr as Ptr)

But – if I try to do that:

dim myCtx as MyContextStruct myCtx.myModel = Nil dim ptrToMyCtx = AddressOf myCtx MyExternalMethodFoo(ptrToMyCtx)

I get the error:

 This item does not exist
 dim ptrToMyCtx = AddressOf [b]myCtx[/b]

Am I not allowed to take the address of a structure?

Can you pass the structure directly?

MeExternalMethodFoo ( s As MyContextStruct )

@Kem Tekinay – Can I? Sure, but in general that’s not very efficient for large structures. Plus, the API is presently defined in the C header:

[quote]struct MyContextStruct {
void* model_this;

DLL_SPEC void MyExternalMethodFoo(struct MyContextStruct* pMyCtx);
…because the C-API call to the dylib is going to pass back a pointer in the model_this field, which will be used on subsequent API calls, passing a structure by value wouldn’t work.

I know it seems silly for a structure that only (presently) contains a single pointer, but there are many other more complex structures that need to be passed in and out of the C-API dylib, so I need to get this process to work correctly – I figured I might as well start simple.

Change this to:

Declare Function Test Lib “filename” MyExternalMethodFoo(ByRef myCtxPtr As StructureName)

@JulianS - Thank you – that DOES get rid of the compile / link, however the correct syntax is:

[quote]soft declare sub MyExternalMethodFoo lib “filename” (ByRef myCtxPtr As StructureName)
However, even though my “filename” path to the dylib is absolute and correct, AND I know the dylib is built for 64-bit, AND the correct C-API symbol is in the .dylib, I’m getting a Function Not Found Exception.

I went through this a few months ago when I was testing .dylib calling – there was SOME MAGIC – can’t recall what that was. I subsequently changed over to building the dylib as a Framework, which is how my other C-API calling test is built. So I need to “rediscover the magic”.

Nice Stephen, sorry I can’t help any further as my dylib knowledge is zero.

Hi @Stephen Greenfield

Put the “.dylib” along the executable file inside the bundle. This is something you can do adding a Compilation Step -> Copy Files and choosing App parent Folder as destination