Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does azure website support p/invoke to load native c++ dll

I've found this says azure web/worker role can load native c++ dll. Does azure website also support this?

My site is a mvc site that p/invoke a native c++ dll which read files from local drive and does some calculations. the reason i'd prefer azure website is because it starts from free.

Thanks.

like image 617
Xin Avatar asked Oct 11 '13 16:10

Xin


2 Answers

Azure websites can also load native dlls. I just made it work.

Here are the steps (referred from here):

  1. Compile your solution.

  2. Right click on the managed project and select "Add/Existing Item". Do not use "Add Reference".

  3. Navigate to your compiled native DLL and select it (adjust file types as needed).

  4. Click on the down arrow in the "Add" split button and select "Add As Link".

  5. Right click on that freshly added file and select "Properties".

  6. Make sure "Build Action" is "Content" and "Copy To Output Directory" is set to "Copy always" or "Copy if newer".

Note: in step 2, you should right click on the project, so that the dll will be copied to the bin folder, and uploaded to Azure server. If you put it in some folder instead of under the project directly, the dll will be copied to /bin/somefolder, which is still invisible.

Hope this helps.

like image 167
user2998273 Avatar answered Sep 22 '22 18:09

user2998273


You can load a native DLL, but there are some requirements. First, it must be targeting x64, not x86.

Also, you must build it against the proper toolset:

By default, only the Visual C++ runtime libraries for Visual C++ 2008 are installed on Windows Azure worker and web roles. Therefore, native code compiled against the Visual C++ runtime library for Visual C++ 2010 or Visual C++ 2005 will fail to load in worker and web role instances. If you have both Visual Studio 2008 and Visual Studio 2010 installed on the same computer you can use the native multi-targeting feature of Visual Studio 2010 to build native libraries for your application with the Visual Studio 2008 platform toolset (compiler, linker, headers, and libraries). For more information about using Visual Studio 2010 to build an application with the Visual Studio 2008 platform toolset see C++ Native Multi-Targeting (http://go.microsoft.com/fwlink/p/?LinkId=231170).

Alternatively, you can setup a startup task that runs elevated which copies the requirements for your native DLL onto the server.

like image 31
Reed Copsey Avatar answered Sep 23 '22 18:09

Reed Copsey