Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use DLLs with Visual Studio Mac

I have an application that uses a third party DLL. Is there a way in Visual Studio for Mac to write an application to access it the same way as I can on windows?

like image 278
SteveFerg Avatar asked Dec 24 '22 23:12

SteveFerg


1 Answers

It depends:

  1. Managed .NET DLL: Can be imported and used the same way as in VS on Windows
  2. Native DLL: can't be used directly. You'll need to build it for your target system, OSX in your case.

If you have C/C++ code you should be able to build it for OSX (with GCC for example) if it doesn't have some foreign (Windows) platform specific code. Then you can use the compiled *.so / *.dylib file directly. But you'll need to tell the .NET Runtime (Mono for example on OSX) to use the different file using a DllMap configuration file (see http://www.mono-project.com/docs/advanced/pinvoke/dllmap/ for examples).

The sources you've linked look like they're for Unix, so the chance to be able to build them on OSX are pretty good (there's a Makefile and the resulting binary would be libswe.so on Unix). You could try to pass the -dynamiclib parameter to GCC to get a OSX specific libswe.dylib (What are the differences between .so and .dylib on osx? seems to be a good answer about dylib)

If you have the binary of your DLL for OSX, you just need a configuration file for your .NET application, which could look like this:

<configuration>
    <dllmap os="osx" dll="libswe.dll" target="libswe.dylib"/>
<configuration/>

It tells the .NET Runtime to import the symbols from libswe.dylib instead of libswe.dll if the current OS is OSX.

like image 139
Sevo Kukol Avatar answered Jan 04 '23 22:01

Sevo Kukol