Thursday, February 26, 2009

Visual Studio express - problems with 32bit DLLs on 64bit OS.

When you are writing any application in Visual Studio 2005/2008 you can target the application to x86, x64 or by default to AnyCPU. Anytime you want to use 32bit only DLL, you have to set target to x86, otherwise your application will crash on 64bit OS.

However, you can't target your application to specific platform in Visual Studio 2005/2008 express edition! Express editions are targeted to AnyCPU, that will allow them to run in 64bit mode on 64bit OS. The problem is when you will link any 32bit DLL to this project. Your application will crash on 64bit OS as soon as it will try to call any function from the 32bit DLL.

Solution is simple. In full version of Visual studio, just target your application to x86 platform. If you need to do this in express edition, you have to do this manually by edditing your .csproj file. All you need is add one line into this file - <platformtarget>x86</platformtarget>.

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>9.0.21022</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{DF511499-467A-4B2D-873E-5297A2AB4698}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>WoL</RootNamespace>
    <AssemblyName>WoL</AssemblyName>
    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <StartupObject>WoL.Program</StartupObject>
    <SignAssembly>false</SignAssembly>
    <PlatformTarget>x86</PlatformTarget>
</PropertyGroup>

You will find several <PropertyGroup> sections there. Just add the <platformtarget>x86</platformtarget> to all these sections and save the file. Now open your project in VisualStudio and recompile it. It will now run in 32bit even on 64bit OS and everything will be working (application will be forced to run in 32bit mode only).

1 comment:

  1. guys try this dll to fix your problem http://fix4dll.com/d3dx9_43_dll, it helped me, so i think it will help you also!

    ReplyDelete