2

I have code that uses the DllImport attribute to talk with an unmanaged assembly. In OS X, this assembly is installed as a framework.

[DllImport("libraryname", CallingConvention = CallingConvention.Cdecl)]
public static extern void FunctionName();

However, this throws a DllNotFoundException in Mono, presumably because it has not been able to resolve the framework.

I looked in the Mono documentation: http://www.mono-project.com/Interop_with_Native_Libraries

They have this little nugget in there:

Mac OS X platforms have a lib prefix and a .dylib suffix, unless they're a Framework, in which case they're a directory and things get more complicated.

But they don't include any info (as far as I could find) about what I should do if it is a directory. Anyone has experience doing this?

poupou
  • 43,413
  • 6
  • 77
  • 174
sohum
  • 3,207
  • 2
  • 39
  • 63

1 Answers1

4

This solution is pretty simple if you want to interop with a system framework as its location never changes.

For example, if you want to access the CFRelease function in the CoreFoundation framework, use:

[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", EntryPoint="CFRelease")]
public static extern void CFRelease(IntPtr cf);

The Mono loader will load the framework without problem.

Laurent Etiemble
  • 27,111
  • 5
  • 56
  • 81
  • 1
    Yeah, I played around with all the different options. Turns out I just had to do "Library.framework/Library" since the Frameworks directory is already in the search path. – sohum Sep 15 '11 at 21:27