• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

Books that address C++ programming for hardware interaction.

Recently I asked a question regarding the type of language best suited to interact with computer hardware, such as imaging a HDD, sector by sector. I received very good input and have chosen to work with C++.NET.  My follow-up question is as follows:  Does anyone know of a good book that specifically covers interacting with, or programming for, hardware using C++? The amount of 200 points will be awarded to the contributor, that provide the name of a commercially available book and its author, that specifically (or mostly) addresses the area I've mentioned above. Thank you for your help in advance.
0
Mr_Fulano
Asked:
Mr_Fulano
  • 4
  • 3
  • 3
  • +2
4 Solutions
 
AlexFMCommented:
I don't think that such book exists. Hardware access is specific to OS and device, there is not general way. In Windows hardware access usually done using Windows drivers. Some devices are supplied with SDK which can be used to access them. Some devices (like COM ports, non-system drives) can be accessed directly from user mode using CreateFile function. Take a look also at DeviceIOControl API.
You need to be more specific and describe what exactly you want to do.
0
 
pmdwCommented:
C++ ok
C++.Net umm...
I am assuming it is MS Windows os you are using as you say .Net

If your looking at writing a device driver, the last real book I read was The Windows NT Device Driver Book ( A Guide for Programmers) by Art Baker not to sure if its still in print.

If you are looking a more generic solution, you might be better getting a book on assembly I have used IBM PC assember language and programming by Peter Able not to sure if its still in print.

I was recently recommended Professional Assembly Language by Richard Blum as an update,  but I am not to sure as it seems to be very Intel only.

If all else fails you can try the MS DDK. A word of warning! Dont trust the windows DDK documentation blindly it is not very acurate.
0
 
AxterCommented:
FYI:

Driver Experts recommend that you NOT use C++ for driver development.
I believe that MS has a recommendation against using C++ for driver development on their web site.

On a recent seminar that I went to, the speaker recommended using the C++ compiler (*.cpp file) to develop the drivers, but not to use C++ classes.

He recommended using the C++ compiler just to get the added type checking, but to use C code.

In the seminar, some developers stated that they have used C++ classes for driver development, but that you have to be careful when you do so.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
AxterCommented:
Check out the following link for books on driver development:
http://www.osr.com/publications_main.shtml

OSR is one of the leading Consultents on Windows driver development.
0
 
AlexFMCommented:
Yes, newest driver development platform KMDF allows only C language.
0
 
AxterCommented:
FYI:
You can also get a lot of free information via the following MS link, and  you can download the driver development kit for free:
http://www.microsoft.com/whdc/driver/foundation/default.mspx
0
 
grg99Commented:
It all depends on what level you want to interact with the disk.

If there's already an operating system, it's a very good idea to use the OS to read and write the disk.

Most OS's let you get down to the raw block level, on Unix/Linux you read and write the raw disks /dev/rdsk* or similar names.  On Windows you can open the raw volume (if you have admin access).
You can do this without getting down to talking directly to the disk driver or to the disk.  It's much like reading or writing a regular file.


You can access these OS I/O calls from most languages.  Actually, from the .NET languages it's much harder to do this-- as all the system API's have to be funneled through some weird interface.

Like others have suggested, I'd suggest NOT using a .NET language, but something a bit simpler, like C or C++.

If you use C or C++ AND the OS I/O calls, you won't need to do the very difficult job of writing a disk driver, or interacting duirectly with the OS disk driver.  Those are very difficult to do and get all the interlocks and concurrency and  timing considerations just right.

So:  use C or C++, use the OS's API's for disk access, don't try writing your own disk driver.



0
 
Mr_FulanoAuthor Commented:
Wow, you all provided a lot of useful information, and I think I’ll have to increase the points and split them in some equitable manner to compensate those of you that have clearly gone the extra step.  However, let me articulate what I want to do a bit more clearly and perhaps that will shed some light on what I may need in terms of reading / instructional material. Oh and yes, I’m dealing with MS Windows boxes. – I want to write code that will look at a HDD that is attached to a computer as a second drive via USB, or Firewire, and be able to (** without ** interacting with the OS on the second HDD) copy the HDD, sector-by-sector at the hardware level. That is, I want it to start at sector 0 and copy / verify each sector until it reaches the end of the drive, however large that may be. I want to see all the contents of each sector and copy it regardless of what the OS sees. I would assume that I would have to write some sort of hardware driver that would interact with any raw HDD that I choose to attach. Hope this sheds some light on the subject. Oh, BTW, why not C++ .NET? What is the difference between C++ and C++.NET, I thought it was the same thing, but in a GUI ?
0
 
grg99Commented:
It's really hard to copy a whole disk.  First of all, the disks would have to be of identical size.  This is harder than it seems, as disks often have a few bad blocks that are marked as bad and mapped out of existence.  If you copy to a larger disk, then that larger disk will often be rejected by many utility programs that can figure out what the real disk size is.

 Then do you really want to copy all the "unused" blocks?  What if you get an I/O error on an unused block, or on the duplicate copy of a directory, do you abandon the whole disk copy as being bad?  Also, do you really want to copy hidden things, like boot blocks and partition maps, unalllocated partition space,  and hidden partitions?

There is a HUGE differemnce between C++ and C++.NET.   C++ generates actual machine code, can call all the Windows API's, and runs quite fast.

All the .NET languages generate an intermediate virtual-machine code, cannot directly call any Windows API, and run rather slowly.

0
 
Mr_FulanoAuthor Commented:
GRG99,

Yes, I do want to copy all the blocks, allocated an dunallocated, and yes you can copy (image) to a larger disk without any problems what so ever. However, thats not the issues I want to discuss here. What I'm asking is regarding any books (or really good study material) that will allow me to do what I've described above. I need to be able to write the code so it will interact with a device, much like the code used to connect a device through a USB cable. You're not going through the OS of the attached device, you're simply reading it with your OS. I want my code to use that connection, and do things. . .whatever I program it to do, liketelling me about the drive's geomitry, coping sector by sector, zeroing out the disk, searching the disk at the sector level (what is seen by the OS and what is not), etc.

As far as C++ and C++.Net, is what your saying is that what I've described avove cannot be done at all with C++.Net?

If not where can I get a good C++ compilier?

0
 
grg99Commented:
A good C++ compiler, try www.openwatcom.com for a quite good free one.

For your information  needs, go to www.msdn.com and type in "Createfile" in the search box.,
That page will explain how to open a volume for raw I/O.  Tonce you undersrtand that, click on the links to the left to go to the pages that describe how to get volume information and do I/O.

Again you're going to have problems if you copy a disk to a different sized disk.  Many OS's will complain that you 've specified the wrong number of heads, cylinders, tracks, spare block map, partition table, and more.

Rather than re-invent the wheel, you might google for the very very many existing disk copy programs.  Norton ghost is not very expensive, and certainly cheaper than trying to write your own, even if you value your own time at 5 cents an hour.



0
 
Mr_FulanoAuthor Commented:
GRG99, thanks for the info. I appreciate the time you put into trying to help me and I'll award point later on this evening. Again, thanks for you links and input, as I do find it helpful.
0
 
Mr_FulanoAuthor Commented:
I increased the points from 200 to 500 and did my best to award them in an equitable manner. I tried to give everyone 200 points, but id did not let me as the max is 500. Although the question was not answered fully, the contributers all tried to do the best they could to help me and I appreciate that. I will be asking more questions in the days to come, so helpfully I can award you more points if you assist me. I hope the point spread was found to be just.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now