CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2000
    Posts
    13

    Default Printer Driver Info.

    I need to fetch default printer driver information like
    device name and driver name and it has to work in
    all the Windows Env. WIN 95/98/ME/NT/2K/XP....
    I need to create a DLL for the above task....
    Any comments or help with some sample code please..
    Thanks for your time..

  2. #2
    Join Date
    May 2002
    Location
    India
    Posts
    4
    use

    char *retStr=new char[255];
    ::GetProfileString("windows","device","",returnString,255);

    Hope this will solve your problem

    Regards,
    PMS

  3. #3
    Join Date
    Dec 2000
    Posts
    13
    Hey PMS , thanks for that prompt post...

    That really worked fine......
    However , on WIN NT machine it is returning empty Value....
    I read that it picks up from win.ini File and since the mentioned
    section and key name were absent in my win.ini file on WIN NT
    machine it is displaying Emty String....

    Would you be able to give me any further inputs on this , Pls ...

    Also , I would need to find , if the Printer status is ready ....
    would appreciate your help on this issue too , if I am not demanding too much......

  4. #4
    Join Date
    May 2002
    Location
    India
    Posts
    4
    Ok no probs.Try the below method.Hope this will solve.

    char *GetPrinterName()
    {
    DWORD dwValues;
    DWORD idw;
    LONG lReturn;
    HKEY hQKey = NULL;
    TCHAR szStr[200];
    DWORD dwValueNameLen,dwValueLength;
    DWORD dwType;
    BOOL Ok;

    unsigned char *szValue=new unsigned char[255];
    char *szErrorValue=new char[255];
    strcpy(szErrorValue,"No printers");


    lReturn = RegOpenKeyEx (HKEY_CURRENT_USER,"Printers",0L,KEY_ALL_ACCESS, &hQKey);
    Ok = (lReturn == ERROR_SUCCESS);
    if (Ok)
    {

    lReturn = RegQueryInfoKey( hQKey, NULL, NULL, NULL
    , NULL, NULL, NULL, &dwValues, NULL, NULL, NULL, NULL );

    Ok = (lReturn == ERROR_SUCCESS);
    }
    if(Ok)
    {
    for ( idw=0; ((idw<dwValues) && Ok); idw++) {
    dwValueNameLen = 200;
    dwValueLength=255;
    lReturn = RegEnumValue(
    hQKey
    , idw
    , szStr
    , &dwValueNameLen
    , NULL
    , &dwType
    , szValue
    , &dwValueLength
    );
    if(strcmp(szStr,"DeviceOld")==0)
    {
    for(unsigned int index=0;index < strlen((char *)szValue);index++)
    {
    if(szValue[index]==',')
    {
    szValue[index]='\0';
    break;
    }
    }
    return (char *)szValue;
    }
    }
    }

    if (hQKey != NULL)
    {
    RegCloseKey (hQKey);
    hQKey = NULL;
    }
    return szErrorValue;
    }


    You can get the status of the printer from PRINTER_INFO_2 and
    JOB_INFO_2 structures.... Any further queries you can feel free to ask.

    Regards,
    PMS

  5. #5
    Join Date
    Dec 2000
    Posts
    13
    Hi PMS ,
    Full Marks... That's Perfect... It is really working fine now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured