Thread: need help with the GetVolumeInformation function

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    104

    need help with the GetVolumeInformation function

    I need help with the GetVolumeInformation function.
    Below is the code I've been working with.
    I'm hoping someone can save me some time in figuring this out.
    Thanks in advance.

    /* GetVolInfo.c */
    /* to be used for interface with ForTran */

    #include <windows.h>
    #include <commctrl.h>
    #include <stdio.h>
    #include <string.h>

    //#define MSGSIZE 80
    //
    LPCTSTR HD = "C:\";

    //
    void main(char *CSN)
    //extern void GetVolInfo(char *CSN)
    {
    FILE *fptr;
    fptr = fopen("TestGetVolInfo.txt", "w");

    //
    GetVolumeInformation(HD,
    ,
    NULL,
    CSN,
    255,
    NULL,
    NULL,
    FILE_READ_ONLY_VOLUME,
    FAT,
    NULL
    );
    fprintf(fptr,"C: Serial Number = %s",CSN);
    return (0);
    }

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    104
    This is my latest. I've made some progress. I can get an executable and it gets me a value, but it doesn't look right to me.
    I was expecting numbers and letters, but I'm getting something else. Also, I keep getting two compiler warnings for the FileSystemBuffer argument - "Suspicious pointer converstion" .
    Would appreciate the help.

    /* GetVolInfo.c */
    /* to be used for interface with ForTran */

    #include <windows.h>
    #include <commctrl.h>
    #include <stdio.h>
    #include <string.h>

    //#define MSGSIZE 80
    //
    LPCTSTR HD = "C:\\";
    LPTSTR HDBUF,VNB;
    LPDWORD MCL;
    //int FSF=FS_FILE_COMPRESSION;
    int FSF=FS_UNICODE_STORED_ON_DISK;
    DWORD FSNB=255;
    //
    FILE *fptr;

    void main(char *CSN)
    //extern void GetVolInfo(char *CSN)
    {


    //
    GetVolumeInformation(HD,
    VNB,
    255,
    &CSN,
    MCL,
    &FSF,
    HDBUF,
    FSNB);
    fptr = fopen("TestGetVolInfo.txt", "w");
    fprintf(fptr,"C: Serial Number = %s",&CSN);
    }



  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Firstly, fix the

    Code:
    void main(char *CSN)
    There's so much wrong with that...........

    Anyway....heres a working example

    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    int main(void)
    {
    
    LPCTSTR szHD = "C:\\";
    UCHAR szFileSys[255],szVolNameBuff[255];
    DWORD dwSerial,dwMFL,dwSysFlags;
    BOOL bSuccess;
    
    bSuccess = GetVolumeInformation(szHD,(LPTSTR)szVolNameBuff,
    					 255,&dwSerial, &dwMFL,&dwSysFlags,
    					 (LPTSTR)szFileSys,255);
    
    if(!bSuccess){
    	cout << "Error number " << GetLastError() << endl;
    	return 1;
    }
    if(szVolNameBuff[0] == NULL)
    cout << "Vol Name not present" << endl;
    else
    cout << "Vol Name is " << szVolNameBuff << endl;
    cout << "Vol Serial is " << dwSerial << endl;
    cout << "Max Filelength is " << dwMFL << " chars" << endl;
    cout << "Filesystem is " << szFileSys << endl;
    
    
    return 0;
    }

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    104
    Just wanted to say thanks for the code Fordy.
    It worked out pretty good.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM