?
Solved

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

Posted on 2009-12-28
7
Medium Priority
?
446 Views
Last Modified: 2013-12-17
Hi,

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.

http://msdn.microsoft.com/en-us/magazine/cc164123.aspx

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
http://www.advantech.com.tw/products/1-MS-s-12-bit-16-ch-PCI-Multifunction-Cards/mod_1-2MLGXI.aspx

Thanks,

Ward.



0
Comment
Question by:whorsfall
  • 4
  • 3
7 Comments
 
LVL 41

Expert Comment

by:graye
ID: 26138090
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.
0
 
LVL 1

Author Comment

by:whorsfall
ID: 26142156
Hi,

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).


Thanks,

Ward
0
 
LVL 1

Author Comment

by:whorsfall
ID: 26142213
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.

Thanks,

Ward
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 41

Accepted Solution

by:
graye earned 2000 total points
ID: 26142883
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.   http://dependencywalker.com/.
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.
0
 
LVL 1

Author Comment

by:whorsfall
ID: 26143007
Cool,

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.

Thanks,

Ward

0
 
LVL 41

Expert Comment

by:graye
ID: 26143058
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.
0
 
LVL 1

Author Closing Comment

by:whorsfall
ID: 31670662
Awsome - points well earned big thanks :)
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 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