Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. adding a different references depending on the system.(32 bit or 64 bit)

adding a different references depending on the system.(32 bit or 64 bit)

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    prasadbuddhika
    wrote on last edited by
    #1

    i have project that need to reference a mathlab dll, but this dll is wroking only on 64 bit systems, because i build the dll in my 64 bit pc, when i try to run this project in 32 bit pc i get an error, but when i run the project with the dll which is built in 32 pc it works fine. so my problem is how can i add the reference at run time depending on the system(32/64), so then i don't want to keep two separate projects. and is there any way that i can add the reference that can be selected at runtime, but the doubt i'm having is i need a reference (one of them 32 dll or 64 dll) to build the project. appreciate your ideas. thanx in advance.

    L 1 Reply Last reply
    0
    • P prasadbuddhika

      i have project that need to reference a mathlab dll, but this dll is wroking only on 64 bit systems, because i build the dll in my 64 bit pc, when i try to run this project in 32 bit pc i get an error, but when i run the project with the dll which is built in 32 pc it works fine. so my problem is how can i add the reference at run time depending on the system(32/64), so then i don't want to keep two separate projects. and is there any way that i can add the reference that can be selected at runtime, but the doubt i'm having is i need a reference (one of them 32 dll or 64 dll) to build the project. appreciate your ideas. thanx in advance.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Assuming you have two native code DLLs, one with 32-bit code, the other 64-bit code, there are basically two ways AFAIK: 1. force your app to always run in 32-bit mode using shortcut properties. Or build your managed app for "x86"; it will always require the 32-bit DLL. 2. build your managed app for "Any CPU". It will get launched as 64-bit whenever possible, and then it will need all-64-bit DLLs. As you normally don't explicitly load native DLLs from managed code, the best way to cope would be to have two prototypes and a stub for every native method, like so (note different DLL names!):

      static class mathlabStub {
      private static bool use64bit;

      [DllImport("mathlab32.dll", EntryPoint=someFunction)] public static extern int someFunction32(...);
      [DllImport("mathlab64.dll", EntryPoint=someFunction)] public static extern int someFunction64(...);

      public static int someFunction(...) {
      if (use64bit) return someFunction64(...);
      return someFunction32(...);
      }

      and then you have to set use64bit once, maybe like so: use64bit=sizeof(IntPtr)==8; use64bit=Marshal.SizeOf(typeof(IntPtr))==8; :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      modified on Sunday, April 17, 2011 11:51 AM

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups