Preprocessor directive in C# for importing based on platform

Viewed 22739

Looking for a preprocessor directive in c# for importing dll based on whether the executable is 64bit or 32 bit:

#if WIN64
[DllImport("ZLIB64.dll", CallingConvention=CallingConvention.Cdecl)]
#else
[DllImport("ZLIB32.dll", CallingConvention=CallingConvention.Cdecl)]
4 Answers

unload and edit the .csproj file, add:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
    <DefineConstants>WIN64;$(DefineConstants)</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
    <DefineConstants>WIN64;$(DefineConstants)</DefineConstants>
  </PropertyGroup>

use:

#if WIN64
...
#endif

Regards

Related