Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Books that address C++ programming for hardware interaction.

Posted on 2006-05-11
13
Medium Priority
?
441 Views
Last Modified: 2008-02-01
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
Comment
Question by:Mr_Fulano
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 150 total points
ID: 16666416
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
 
LVL 2

Assisted Solution

by:pmdw
pmdw earned 450 total points
ID: 16668338
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
 
LVL 30

Assisted Solution

by:Axter
Axter earned 450 total points
ID: 16668447
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 30

Expert Comment

by:Axter
ID: 16668482
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 16668648
Yes, newest driver development platform KMDF allows only C language.
0
 
LVL 30

Expert Comment

by:Axter
ID: 16668766
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
 
LVL 22

Expert Comment

by:grg99
ID: 16671176
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
 

Author Comment

by:Mr_Fulano
ID: 16671972
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
 
LVL 22

Expert Comment

by:grg99
ID: 16673516
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
 

Author Comment

by:Mr_Fulano
ID: 16675222
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
 
LVL 22

Accepted Solution

by:
grg99 earned 450 total points
ID: 16677506
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
 

Author Comment

by:Mr_Fulano
ID: 16679019
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
 

Author Comment

by:Mr_Fulano
ID: 16679044
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

564 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