Using 32 Drivers / Libraries from C# in 64 Bit Windows?

Posted on 2009-12-28
Last Modified: 2013-12-17

I am trying to determine the risks profile of doing the following:

I want to write a C# 3.5 .NET application that calls some 32 Bit code
using PInvoke. I really want to find out what are the risks
and hidden gotchas in doing this. (This is for a Data Acquition
card). So I assume there would be a software driver for the card.

From what I can see is I would need to know all the
function prototypes for the DllImport of everything
I need to call and have to define them all.

Ok here are my questions:

1.      Are the any other issues I should be concerned about?

2.      Would there be any issues with this working under 64 Bit
                      Windows. I would like to target Vista 64 Bit and Windows 7?
3.  Is the hardware model different between Windows Vista 32 and
    Windows 7 x64? (I assume it would be). In other words can
    a 32 bit driver be made to work under 64 bit.
Hi. These are complex questions so I am going to award maximun
points for the best answer on this.

BTW: URL to the Card so you have some context information:

Advantech PCI-1712



Question by:whorsfall
    LVL 41

    Expert Comment

    First of all, you've got to make sure that you've got a 64-bit driver for the device.   I looked at the URL you provided, and it doesn't seem to be the case.
    Normally the way it works is... you install a 64-bit driver, and then have a 3rd-party DLL that provides access to the driver.  Typically both the driver and the DLL are either both 32-bit or both 64-bit.   Then your application uses P/Invoke-style calls to the DLL... again both your applicaiton and the DLL are both 32-bit or both 64-bit.
    So, unless they've got a 64-bit driver, you're stuck... as you can NOT install a 32-bit device driver in a 64-bit Windows OS.

    Author Comment


    Thanks that was great.

    Had some other quick questions:

    1.  Was I correct about the PInvoke about having to know all the declarations before I call the Lib file? Is there anyway I can get something to scan the file to generate them automatically?

    2. Is it only Drivers that can access the hardware directly to talk to harware directly I assume it can only go through a Windows driver, or can C# code manipulate it directly. (I am trying to understand the dividing line here).



    Author Comment

    Oops forgot to ask:

    1. Would a 32 Bit Windows driver work on 32 bit Windows 7?
    2. Would a 64-bit Windows driver work on 65-bit Windows 7?

    I have tried to search but cant see any clear info if they are compatible at this level.


    LVL 41

    Accepted Solution

    By the numbers...
    1)  Yes,  you can use the P/Invoke method as an alternative to importing a LIB file.   The ability to recreate a LIB file after the fact, is unlikely and highly dependent upon how the DLL was originall created (What language, what compiler, etc).   You typically don't create a LIB file after the fact... as this step is more appropriately performed by the original author during the compile phase.   I typically use the Depends tool to view the exposed "entry points" into a DLL.
    2) Drivers only talk to the inner most part of the operating system, called "ring 0".   Oridinary applications (ring 2) do not have access to this "processor level".   The bridge between a device driver and an oridinary application is typically via a DLL file.   So, you'd typically need two files... one is the device driver, the other is the DLL that acts as an intermediary.
    1&2)  While it's true that 64-bit operating systems can "host" and run 32-bit applications, this does not apply to device drivers.   For the same reasons as above, there must be a perfect match between device drivers and the operating system.   So, that means a 64-bit OS must use only 64-bit drivers.  There is no way to install a 32-bit driver on a 64-bit OS (and also the other way around... you can not install a 64-bit driver on a 32-bit OS).
    I think you're still stuck at the fact that there is no 64-bit driver for the device.   There is absolutely no way to get around this simple fact.   The only option would be to install a 32-bit operating system.

    Author Comment


    Awsome info.

    Sorry I did not phrase my last two questions correctly (event though you gave me great info :))

    I meant to say - out of general curiosity:

    1. Would a 32 Bit "Vista" (x86) Windows driver work on 32-bit (x86) Windows 7?
    2. Would a 64-bit "Vista" (x64) Windows driver work on 64-bit (x64) Windows 7?

    In other words assuming what you said about the 32/64 bit strucutre is the driver model the same, as I would understand that there are some specific Windows 7 features that might not be avaiable though as it would not be a native driver.



    LVL 41

    Expert Comment

    Ah yes... there normally isn't much of a difference between Vista and Win7.   So, if you can find a Vista x64 driver, the chances are that they'd work fine in Win7 x64.
    That's correct... if there is any difference, it might just be a missing feature.

    Author Closing Comment

    Awsome - points well earned big thanks :)

    Featured Post

    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

    Join & Write a Comment

    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…
    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    728 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

    23 Experts available now in Live!

    Get 1:1 Help Now