Azure Web Sites Native C++ DLL (p/invoke)

Sometimes you need improve performance of your code or using library which written on other language. Today we will talk how to create x64 C++ library and how to invoke method in C# Azure Web Site.

  1. Create C++ dll library in VS
  2. In project settings (Linker -> Advanced) set Target Machine to MachineX64 (/MACHINE:X64)
  3. In project setting (C/C++ -> Advanced) set Calling Convention to __cdecl (/Gd)
  4. For example create header and source files with name ExpressionExecuter
  5. In header file define prototype function:
  6. Source file realize method ValidateExpression:
  7. Configure Azure Web Site using method described here
  8. Now we need to realize invoke method in C# project:
  9. Now you can use C++ code using p/invoke in Azure Web Site project:
  10. Don’t forget set X64 configuration settings on staging or production azure web site (Configure Tab -> General -> Platform) select 64-BIT option.


Now you have performance code in your C# Azure Web Site project 😉

Leave a Reply

Your email address will not be published. Required fields are marked *