Thread: can i read msinfo32.exe file in windows by c program

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    1

    can i read msinfo32.exe file in windows by c program

    hello frnds ,
    i m in difficulty i have to read some information from msinfo32.exe or i copy msinfo32.exe containing information into some other file by c program , can any one sugget me how i proceed by an example
    i tried to open it by fopen for reading but it is in binary so of no use

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Of course it's in binary. All executables are binary. What were you hoping to see?
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    fopen has a binary mode
    Code:
    fp = fopen(filename, "rb");
    also, use fread for binary reads.

  4. #4
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    fopen is always binary mode (using 'b' is usually just a notational convention).

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by @nthony View Post
    fopen is always binary mode (using 'b' is usually just a notational convention).
    do you know if it ever has an effect?

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by @nthony View Post
    fopen is always binary mode (using 'b' is usually just a notational convention).
    I believe we had posts here just recently that say this is wrong.

    http://cboard.cprogramming.com/showt...ht=binary+file

    http://cboard.cprogramming.com/showt...ht=binary+file

    I can't find the one I saw recently, where it was mentioned that some O/S's get touchy about how you open a file, whether in text or binary mode.

    Edit: Found it.

    Post by brewbuck: http://cboard.cprogramming.com/showp...3&postcount=10
    Last edited by MacGyver; 06-19-2007 at 06:48 PM.

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    thanks MacGyver, but does anybody know what those differences are?

  8. #8
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    MSDN: fopen might be helpful.

    Also, to clear things up, C Standards:
    fopen
    I/O Streams
    clearly define that "b" shall have "no effect". So whatever effect an OS wants to put on it outside of the standards is not C's or fopen's fault (as brewbuck said). But, it is not exactly the OS's fault either as they usually should provide a function from their own API that supercedes the standard function they have altered, in which case you should be using this function instead if you want to avoid problems (as is the case with winAPI's CreateFile).

  9. #9
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Well, the man page on my Linux box says this:
    The mode string can also include the letter ``b'' either
    as a last character or as a character between the charac-
    ters in any of the two-character strings described above.
    This is strictly for compatibility with ANSI X3.159-1989
    (``ANSI C'') and has no effect; the ``b'' is ignored on
    all POSIX conforming systems, including Linux. (Other
    systems may treat text files and binary files differently,
    and adding the ``b'' may be a good idea if you do I/O to a
    binary file and expect that your program may be ported to
    non-Unix environments.)
    And I can't find anywhere in the C99 standards documentation that says the 'b' will have no effect. You have to be careful that you're not reading things that are written specifically for one environment and treating it as a global truth.
    Last edited by itsme86; 06-20-2007 at 09:42 AM.
    If you understand what you're doing, you're not learning anything.

  10. #10
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Quote Originally Posted by itsme86 View Post
    Well, the man page on my Linux box says this:
    ...You have to be careful that you're not reading things that are written specifically for one environment and treating it as a global truth.
    Ironically, thats exactly what you've done. You've used the Linux man page for a defintion of fopen. Like Windows, Linux is one of the OS's that have changed the standard implementation of the Unix fopen to suit their needs. The link I posted for fopen is the IEEE Unix standard, so I think thats pretty much as "global" as you're going to get.

  11. #11
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Read what you just wrote. The IEEE Unix standard. Unix != Global.

    The link that I provided is the actual ISO C99 standard, in which I could find no reference to the b flag not doing anything.

    The Linux man page I quoted was just to contradict what you had said. The paragraph following the quote is where I linked to the real standard.

    That's 2 strikes. Do you want to try for a 3rd?
    If you understand what you're doing, you're not learning anything.

  12. #12
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Never mind, you are correct. Yes, I was citing the Unix standard for fopen, which incidentally is C99 compliant, so I mistook it as being synonymous with the C99 standard; however I neglected to realize that the Unix implementation of C can still be C99 compliant while still ignoring the 'b' character that C99 states "shall open a file as binary". The quip is that since Unix does not distinguish between "binary" and "text" mode it technically still fulfills the C99 requirements by accepting the premise that any occurence of "text file" can be replaced by "binary file" and vice versa in the following documentation:
    Quote Originally Posted by ISO 9899:7.19.5.3
    r open text file for reading
    w truncate to zero length or create text file for writing
    a append; open or create text file for writing at end-of-file
    rb open binary file for reading
    wb truncate to zero length or create binary file for writing
    ab append; open or create binary file for writing at end-of-file
    r+ open text file for update (reading and writing)
    w+ truncate to zero length or create text file for update
    a+ append; open or create text file for update, writing at end-of-file

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM