IntPtr.Size is Wrong (x64 Vista)???

  • Thread starter Thread starter Jeffrey Walton
  • Start date Start date
J

Jeffrey Walton

Hi All,

I'm working on a Website that uses ASP.Net. I need to call into a few
APIs, the first of which is CreateFile. CreateFile always fails with
INVALID_HANDLE_VALUE.

It seems that 'Dim sz As Integer = IntPtr.Size' returns 4 for the size
even though the docs state I should get 8 on x64 Vista [1]:

The IntPtr type is designed to be an integer whose size is
platform-specific. That is, an instance of this type is expected
to be 32-bits on 32-bit hardware and operating systems, and
64-bits on 64-bit hardware and operating systems.

When I replace the IntPtr to Long for the declaration of CreateFile, I
get a handle back. Unfortunately, the docs tell me otherwise [1], as
does a Visual Basic .NET sample (KB823179) demonstrating CreateFile
[2].

I did not see anything of interest under Solution and Project
properties. What's the trick to get an IntPtr on x64 VB/ASP.Net to
work as advertised?

Wasn't VB much more fun back in the 5.0 and 6.0 days before .Net? I
don't recall having so many problems with the language back then...

Thanks,
Jeff

[1] http://msdn.microsoft.com/en-us/library/system.intptr.aspx
[2] http://support.microsoft.com/kb/823179
 
Hello Jeffrey,


Perhaps something else is forcing the issue....

Have you build your solution as x64, x86 or ANYCPU?

Is IIS set to use 32bit or 64bit?

Seems to me that ANYCPU running under a 32bit process in IIS would use 32bit
pointers even on an x64 system
 
Hi Rory,

Hello Jeffrey,

Perhaps something else is forcing the issue....

Have you build your solution as x64, x86 or ANYCPU?

Is IIS set to use 32bit or 64bit?

Seems to me that ANYCPU running under a 32bit process in IIS would use 32bit
pointers even on an x64 system.
As far as I can tell, there's no way to set this using the IDE. Does
VB/ASP have a setting in the web.config file?

If it matters, I'm using VS 2008 Pro on x64 Vista. So I should not be
getting short changed on features.

Jeff
 
Hello,
I'm working on a Website that uses ASP.Net. I need to call into a few
APIs, the first of which is CreateFile. CreateFile always fails with
INVALID_HANDLE_VALUE.

You need to call CreateFile ? What is the additional feature you are trying
to use ?
It seems that 'Dim sz As Integer = IntPtr.Size' returns 4 for the size
even though the docs state I should get 8 on x64 Vista [1]:

So you are running in a 32 bit process...
The IntPtr type is designed to be an integer whose size is
platform-specific. That is, an instance of this type is expected
to be 32-bits on 32-bit hardware and operating systems, and
64-bits on 64-bit hardware and operating systems.

But you can run a 42 bit process under a 64 bit OS...
I did not see anything of interest under Solution and Project
properties. What's the trick to get an IntPtr on x64 VB/ASP.Net to
work as advertised?

Never done that but
http://blogs.msdn.com/rakkimk/archi...-same-time-on-different-worker-processes.aspx
could perhaps helps...
Wasn't VB much more fun back in the 5.0 and 6.0 days before .Net? I
don't recall having so many problems with the language back then...

You couldn't do that ;-)
 
Hello Jeffrey,
As far as I can tell, there's no way to set this using the IDE. Does
VB/ASP have a setting in the web.config file?

If it matters, I'm using VS 2008 Pro on x64 Vista. So I should not be
getting short changed on features.

I think I may have been getting a little mixed up..

Now that I check (on Win7 x64) there is an ApplicationPool setting which
has to be actively set in order to *allow* 32bit apps to run.

This would seem to be different from what you are describing...

However I would suggest checking out the IIS settings for vista.... I don't
think the one I mentioned can be altereed by a web.config and there may be
others that have to do with what yyou're experiencing.

You may also be better off crossposting this to a web dev newsgroup ( I can't
do that from my newsreader :( or I'd help you out there)

Sorry I couldn't be of more help
 
Hi Patrice,
You need to call CreateFile ? What is the additional feature you are trying
to use ?
I'm working on a project which embeds a customer number within an
executable. Since the customer number changes the PE checksum, we need
to do CreateFile -> CreateFileMapping -> MapViewOfFile ->
CheckSumMappedFile before compressing and making available for
download.
 It seems that 'Dim sz As Integer = IntPtr.Size' returns 4 for the size
even though the docs state I should get 8 on x64 Vista [1]:
So you are running in a 32 bit process...
   The IntPtr type is designed to be an integer whose size is
   platform-specific. That is, an instance of this type is expected
   to be 32-bits on 32-bit hardware and operating systems, and
   64-bits on 64-bit hardware and operating systems.
But you can run a 42 bit process under a 64 bit OS...
The docs should state something like, "Hardware and OS word size are
ignored in favor of what the development environment wants to use. In
the case of a VB/ASP Web Site, good luck in finding out how to force
the IDE into using the native size."
Never done that buthttp://blogs.msdn.com/rakkimk/archive/2007/11/03/iis7-running-32-bit-...
could perhaps helps...
Unfortunatley, I'm using the Web Server that Visual Studio hauls
around.

Thanks for trying,
Jeff
 
Hello Jeffrey,
Unfortunatley, I'm using the Web Server that Visual Studio hauls
around.

Perhaps that's the problem...

Studio is 32bit... No 64bit version exists...

So if it launches the VS WebServer, does that mean that it is also launched
as 32bit app and hence ANYCPU assemblies run as 32bit ?
 
In addition to Rory's response, it's perhaps too late or won't provide those
features you need but .NET 4.0 will include some support for mapped files...
 
Hi Rory,
Studio is 32bit... No 64bit version exists...
That's probably the issue.
So if it launches the VS WebServer, does that mean that it is also launched
as 32bit app and hence ANYCPU assemblies run as 32bit ?
It sounds reasonable. But again, the best I can tell, there's no way
to modify x86/x64/Any. At least its not under the Solution or Project
properties.

Now would also be a good time to thank all the bloggers who have
turned the web into a cesspool of opinion, making it near impossible
to find obscure bits of required information. :)

Jeff
 
Hi Patrice,

In addition to Rory's response, it's perhaps too late or won't provide those
features you need but .NET 4.0 will include some support for mapped files....
I'll settle for getting the stuff that is currently avaliable to work
properly :)
 
Hello Jeffrey,
It sounds reasonable. But again, the best I can tell, there's no way
to modify x86/x64/Any. At least its not under the Solution or Project
properties.

Try... Project Properties... Compile

Advanced Compile Options.... <- you may have to scroll the project options
down to even see this button

Target CPU = X64 rather than ANYCPU <- 3rd last option in VS2008 SP1
 
No problem, thought you would like to know ;-)

Here you'll likely have to handle both the 32 bit case to be able to run
from your 32 bit VS webserver and perhaps have a 64 bit code path when you
run under IIS.

If using IIS 7 is a possible option, you could perhaps do a quick dummy app
to just see if IIS7 runs in 64 bit mode which seems to be the default...
 
Back
Top