Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / December 2005

Tip: Looking for answers? Try searching our database.

Choosing 32 bits vs 64 bits mode of execution

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Emmanuel Stapf [ES] - 02 Dec 2005 20:29 GMT
Hi,

I'm on Windows XP 64 bits and I have a 32 bits .NET assembly which was
compiled without the 32BIT flag, I cannot use corflags to add it because it
is signed and it is not mine. Is there a way in the config file to say it
has to be run in 32 bits mode instead of 64 bits mode?

Thanks,
Manu
Jacky Kwok - 03 Dec 2005 02:08 GMT
> Hi,
>
[quoted text clipped - 5 lines]
> Thanks,
> Manu

Hi:

I think you need to state more clearly about your situation.

What is your assembly type ? exe , dll ?
What Dotnet version the assembly is built to? 1.x , 2.0?

As I know,

if it is executeable EXE assembly and built for dotnet1.x. It will be
always run in 32 bit in 64bit window.

if it is library DLL assembly, it will follow the host application mode.
If a 64bit app uses the DLL, then it is in 64 bit mode. If a 32bit app
uses the DLL, then it is in 32 bit mode.

Hence, the only question is the assembly is a EXE and built for
dotnet2.0. How to control it run in 32bit/64bit mode?

From the MSDN document, "An application built using .NET Framework 2.0
(on a 32-bit or 64-bit machine) by default will run as a native
application (not under WOW64) on a 64-bit machine."

I think there is no method to force the app to run in 32 bit if you
cannot modify the assembly.

It is a good reference for "Managed Code on 64-Bit Windows Platforms"
http://msdn.microsoft.com/chats/transcripts/windows/windows_110904b.aspx

Signature

Jacky Kwok
jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk
jacky@compose_DOT_com_DOT_hk

Jacky Kwok - 03 Dec 2005 03:32 GMT
> Hi,
>
[quoted text clipped - 5 lines]
> Thanks,
> Manu

I try some interesting test.

How about to directly launch the "Main() function in the anycpu
assembly" in a 32 bit host app?

I made some simple testing. All of the following testing are in
WindowsXP 64 bit and using VisualStudio 2005.

//Firstly, a simple Dotnet2.0 app assembly with the mark AnyCPU
//do nothing just to show a window with some info about 32/64 bit
//if run this app standalone, the IntPtr.Size=8

//program.cs
namespace App64
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }
    }
}

namespace App64
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            label1.Text = "64 bit app, IntPtr.Size=" +                
IntPtr.Size.ToString(); //=4 if 32 bit , =8 if 64 bit
        }
    }
}

//////////////////////////////////////////////////////////////

//Secondly, a simple Dotnet2.0 app assembly with the mark x86 (32 bit)
// it will launch the "Program.Main" in above app
namespace App32
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
#if false
            //if anycpu app main class and main() method are public
       //directly amk reference to the assembly (in VS2005)
            App64.Program.Main();

#else
            //if 64 bit app main class and main() method are non-public
       //using reflection

            string path =
System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\App64.exe";
            Assembly assm64 = Assembly.LoadFile(path);
            Type t=assm64.GetType("App64.Program");
            MethodInfo mf = t.GetMethod("Main", BindingFlags.Static |
BindingFlags.NonPublic );
            mf.Invoke(null, null);
#endif

        }
    }
}

//////////////////////////////////////////////////////////////////////
I find that the info which was shown in the Form of "AnyCPU" assembly is
4 (32 bit). That means the AnyCPU assembly is run in 32 bit mode in 64
bit window.

However, it is just a simple testing. I do not sure it it possible in a
complex application.

Signature

Jacky Kwok
jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk
jacky@compose_DOT_com_DOT_hk

Josh  Williams - 03 Dec 2005 20:17 GMT
> Hi,
>
[quoted text clipped - 5 lines]
> Thanks,
> Manu

If the assembly you are refering to is a .exe then there isn't a way to
do this at present. Is there a reason that you need to run this exe
under the 32-bit runtime?

If this is a dll and it is _not_ marked with the "32-bit" flag then you
can use it in either a 32-bit or 64-bit process. The executable which
starts the process determines bitness, so you just need to compile your
.exe with the right switch.

-josh
http://blogs.msdn.com/joshwil
Junfeng Zhang[MSFT] - 10 Dec 2005 05:52 GMT
You can create a 32 bit only application, then call ExecuteAssembly on your
application.

The decision to run MSIL applications as 64 bit is made by OS. There is
nothing you can do.

Signature

Junfeng Zhang
http://blogs.msdn.com/junfeng
This posting is provided "AS IS" with no warranties, and confers no rights

> Hi,
>
[quoted text clipped - 5 lines]
> Thanks,
> Manu

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.