Article View: comp.os.msdos.programmer
Article #1282MicroSoft C v6.0 code prob.
From: P0LU000
Date: Fri, 04 Sep 1992 19:36
Date: Fri, 04 Sep 1992 19:36
125 lines
3337 bytes
3337 bytes
//
// File: t.c
//
// Test out various subroutines quickly and hopefully with min fuss
//
//
void main( int argc, char *argv[] );
#include <stdio.h>
#include <dos.h>
#include <signal.h>
#include <process.h>
#include "t.h"
int get_disk_serial( unsigned char diskno,
char *ser );
int get_byte_form( unsigned char diskno,
long int *i );
A few weeks ago, some people were kind enough to assist me in
writing code that will allow a program to read the disk serial
number (for DOS 4.0 and up).
Well, I adapted the code from a Pascal routine in PC magazine
(July 1992, page 496), and this version will run. The only
problem is that it does not print out the correct disk volume.
The program I've written up so far is included below. Can
anyone here tell me what I'm doing wrong. More importantly,
can anyone tell me how to do it right?
Thanx in advance...
Leslie Mills
********* Program Follows **********
/* sorry for the incredibly bad spacing. I had a horrible time
trying to transfer the file where I could actually post it
*/
void main( int argc, // these variables are not used.
char *argv[] ) // I placed them here out of habit
{
char ser[10]; // disk serial number
int res; // result of function call
res = get_disk_serial( (unsigned char) 3, ser );
if ( res == 0 ) {
printf( "The serial number of drive C: is: %s\n", ser );
} else {
printf( "Call barfed. Big Bad Ugly Error.\n" );
}
return;
}
//
// I grabbed quite a bit of this procedure from:
// PC Magazine, July 1992, page 496
// Written: 92/09/04
//
int get_disk_serial( unsigned char diskno,
char ser[] )
{
long int i; // This will hold the function result
char *hexdigits = "0123456789ABCDEF";
int res;
union REGS inregs, outregs;
struct SREGS segregs;
inregs.h.ah = 0x69; // DOS fcn call 69h : serial number code
inregs.h.al = 0x00; // read from disk, don't write!
inregs.h.bl = diskno; // read from disk number in diskno
inregs.x.dx = (unsigned int) &i; // data pointer
res = int86x( 0x21, &inregs, &outregs, &segregs );
if ( outregs.x.cflag ) {
// my ambiguous way of displaying an error message
printf( "Little Fluffy took a round, better take him to the vet.\n" );
} else {
printf( "Yeah!\n" );
}
//*- Now long int variable i should have disk serial number
printf( "Byte value of i: %lX\n\n", i );
ser[0] = hexdigits[ i >> 28 ];
ser[1] = hexdigits[ (i >> 24) & 0xf ];
ser[2] = hexdigits[ (i >> 20) & 0xf ];
ser[3] = hexdigits[ (i >> 16) & 0xf ];
ser[4] = '-';
ser[5] = hexdigits[ (i >> 12) & 0xf ];
ser[6] = hexdigits[ (i >> 8) & 0xf ];
ser[7] = hexdigits[ (i >> 4) & 0xf ];
ser[8] = hexdigits[ i & 0xf ];
ser[9] = '\0';
printf( "We reached here all right...\n" );
return( 0 );
}
Technical Details
Message-ID:
<04SEP92.16856055.0215@UNBVM1.CSD.UNB.CA>Path:
arc1-ca.pugleaf.net!sparky!uunet!utcsri!torn!csd.unb.ca!UNBVM1.CSD.UNB.CAShow Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!torn!csd.unb.ca!UNBVM1.CSD.UNB.CA From: P0LU000 <P0LU@UNB.CA> Subject: MicroSoft C v6.0 code prob. Message-ID: <04SEP92.16856055.0215@UNBVM1.CSD.UNB.CA> Lines: 127 Sender: usenet@UNB.CA Organization: The University of New Brunswick Date: Fri, 4 Sep 1992 19:36:26 GMT