Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
i need a vb.net code to determine if 32 or 64 bit operation is ?
Posted

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Apr-11 15:45pm    
Abhinav, this is not too bad, my 5, but I think you're trying to answer the wrong question.
Your samples show "what is the version of OS is installed on the machine writing the current code?".

I think the Question really is: "Is the current code 32-bit or 63-bit"? On 64-bit systems, it can be both; 32-bit software can run on WoW64, see http://en.wikipedia.org/wiki/WoW64.
At the same time, it's easier.

Please see my Answer,
--SA
Abhinav S 17-Apr-11 1:15am    
Well the OP has made it hard for us to interpret his question. Not sure what he actually wanted.
Thanks for the 5.
Sergey Alexandrovich Kryukov 17-Apr-11 1:25am    
Of course. I'm also not 100% sure, but I think my interpretation is most likely correct, and the answer is simple (and useful as you correctly put it :-).
--SA
Abhinav S 17-Apr-11 9:40am    
Your answer is surely useful - I will try and use it sometime as well. Thanks.
Do you only need to know which code is running by the caller: 32- or 64-bit? It this is just this, it's way too simple:

C#
static int HowManyBits {
    get {
        System.IntPtr ptr = System.IntPtr.Zero;
        return System.Runtime.InteropServices.Marshal.SizeOf(ptr) * 8;
    }
}


For example,

C#
static void Main(string[] args) {
    System.Console.WriteLine( string.Format("{0}-bit", HowManyBit) );
}


will output "32-bit" or "64-bit".

Please also see my comment to the Answer by Abhinav.

—SA
 
Share this answer
 
v2
Comments
Abhinav S 17-Apr-11 1:14am    
Very useful answer. My 5 (and goes into my bookmarks as well).
Sergey Alexandrovich Kryukov 17-Apr-11 1:23am    
Thank you very much, Abhinav,
By the way, it simply follows Microsoft documentation of porting between 32 and 64 bits in a most straightforward way, cannot be wrong.
Abhinav S 17-Apr-11 9:41am    
You answered it, so unlikely it is wrong anyway. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900