Solved

dll for 32bit and 64bit

Posted on 2012-03-27
9
536 Views
Last Modified: 2012-04-02
hello there,
I have a source code for a 32bit and 64bit dll file on VS2010..
I would like to know how to make the app load the correct dll file on run time..
so if its a windows 32bit load the 32bit dll or if its 664bit then load the correct dll file..
how can I do this?
0
Comment
Question by:XK8ER
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
You can check the size of an IntPtr. If it's 4, then you are in 32-bit; if it's 8, then you are on 64-bit. Then you can load the assembly dynamically.

e.g.

Imports System.Reflection

...

Dim loadedAssem As Assembly = Nothing

If System.Runtime.InteropServices.Marshal.SizeOf(GetType(IntPtr)) = 8 Then
    loadedAssem = Assembly.LoadFile("path\to\64bit\assembly.dll")
Else
    loadedAssem = Assembly.LoadFile("path\to\32bit\assembly.dll")
End If

Open in new window

0
 
LVL 16

Expert Comment

by:HooKooDooKu
Comment Utility
VS2010 gives you all sorts of build options.  Why not simply name the resulting application and DLL differently for 32 and 64 bit versions of the project:
My.exe + My.dll
My64.exe + My64.dll.
Have the 32 bit version link to My.lib import library and the 64 bit version link to My64.lib import library.
0
 
LVL 1

Author Comment

by:XK8ER
Comment Utility
somehow I have a project that works a bi different..
when I go to VS2010 > properties > references > I see component Name.
when I compile the exe file and run it.. it knows which dll file to load 32 or 64 dll..
both dll files are located in C:\Windows\System32
hows that possible?
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
May be its a loader component that you are referencing and it loads and uses a different DLL based on 32 vs 64 bit using the technique suggested by kaufmed.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:XK8ER
Comment Utility
when I look at the path from
VS2010 > properties > references > componentName.

Interop.componentName.dll
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
>>I have a source code for a 32bit and 64bit dll file on VS2010..

OK - BUT that may well be different technology to the other dll you talk about.
A .net program/library does NOT compile to a specific executable code, it compiles to an intermediate which should be 32/64 bit independant.  When the app/dll then runs the .net environment compiles it to either the 32 bit or the 64 bit version as required.  So one .net dll will cover both 32 and 64 bit operating systems.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
When the app/dll then runs the .net environment compiles it to either the 32 bit or the 64 bit version as required.  So one .net dll will cover both 32 and 64 bit operating systems.
Not to say I'm not doing something wrong, but I have run into issues where using a 3rd-party library that was compiled for a specific environment (ODP.NET) did force me to pick whether or not I was targeting a 32- or 64-bit environment in order to properly load the 3rd-party library.
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
Hmmm - maybe instead of will I ought to have said should.
0
 
LVL 32

Expert Comment

by:sarabande
Comment Utility
system32 should not contain 64-bit dlls. if it does nevertheless the dll either was never used, or the 64-bit program that loads it, explicitly uses the path to system32 folder, or the 64-bit dll isn't 64-bit but 32-bit (only the name contains 64 ???).

Sara
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now