Function to Set Default Printer Florida

SetPrinter is a simple DLL COM that enables you to programmatically set the default printer:

Local Companies

Keylogger
001-9900000000
Address1 street
Province, FL
MFG/EDP, Inc.
(305) 292-2660
1224 South St.
Key West, FL
Nextlevel Information Solutions
727-821-7444
700 Central Ave
St. Petersburg, FL
Progressive System Solutions Inc
407-523-7676
4019 Clarcona Ocoee RD
Orlando, FL
Acusoft
407-658-9888
11869 High Tech Ave
Orlando, FL
design barcode label
0019800000000
Lane
City, FL
Keylogger
001-9900000000
Address1 street
Province, FL
Office Management Solutions Inc
813-963-5582
5802 Taywood DR
Tampa, FL
Summit Software Design
727-823-1000
100 2nd Ave S
St. Petersburg, FL
Riptide Software
407-384-8818
3452 Lake Lynda Dr
Orlando, FL

provided by: 
Originally published at Internet.com


Environment: Windows NT4 SP3; Developed with Visual C++ 6 SP3

SetPrinter is a simple DLL COM that enables you to programmatically set the default printer: * The problem that I faced is that if you attempt to specify the default printer from an application, that printer is not actually realized as the default printer by Windows immediately.

You can resolve this problem by doing the following: * First, install the driver printer on your machine; * If you work on Windows 2000, you must use 'SetDefaultPrinter' followed by the printer's name. * If you work on Windows 98 or Windows NT 4 you must first call the OpenPrinter function in order to retrieve the printer handle. Then you need to call the GetPrinter function twice in order to obtain the printer informations. You then need to call the WriteProfileString function (Windows NT) * Finally, you must notify all windows of this new Windows setting as follows: lResult = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0L, 0L, SMTO_NORMAL, 1000, NULL);

Or instead of going through all of that, you can use my COM component and its DPSetDefaultPrinter method. Here is the code for that method so that you can see all that needs to take place to perform a seemingly very simple task. STDMETHODIMP CCustomPrinter::DPSetDefaultPrinter(BSTR pPrinterName, int *Result) { USES_CONVERSION; BOOL bFlag; OSVERSIONINFO osv; DWORD dwNeeded = 0; HANDLE hPrinter = NULL; PRINTER_INFO_2 *ppi2 = NULL; LPTSTR pBuffer = NULL; LONG lResult; // What version of Windows are you running? osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osv); if (!pPrinterName) *Result = 0; return S_FALSE; // If Windows 95 or 98, use SetPrinter... if (osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { // Open this printer so you can get information about it... bFlag = OpenPrinter((char*)OLE2CA(pPrinterName), &hPrinter, NULL); if (!bFlag || !hPrinter) *Result = 0; return S_FALSE; // The first GetPrinter() tells you how big our buffer should // be in order to hold ALL of PRINTER_INFO_2. Note that this will // usually return FALSE. This only means that the buffer (the 3rd // parameter) was not filled in. You don't want it filled in here... GetPrinter(hPrinter, 2, 0, 0, &dwNeeded); if (dwNeeded == 0) { ClosePrinter(hPrinter); *Result = 0; return S_FALSE; } // Allocate enough space for PRINTER_INFO_2... ppi2 = (PRINTER_INFO_2 *)GlobalAlloc(GPTR, dwNeeded); if (!ppi2) { ClosePrinter(hPrinter); *Result = 0; return S_FALSE; } // The second GetPrinter() will fill in all the current information // so that all you need to do is modify what you're interested in... bFlag = GetPrinter(hPrinter, 2, (LPBYTE)ppi2, dwNeeded, &dwNeeded); if (!bFlag) { ClosePrinter(hPrinter); GlobalFree(ppi2); *Result = 0; return S_FALSE; } // Set default printer attribute for this printer... ppi2->Attributes |= PRINTER_ATTRIBUTE_DEFAULT; bFlag = SetPrinter(hPrinter, 2, (LPBYTE)ppi2, 0); if (!bFlag) { ClosePrinter(hPrinter); GlobalFree(ppi2); *Result = 0; return S_FALSE; } // Tell all open applications that this change occurred. // Allow each application 1 second to handle this message. lResult = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0L, (LPARAM)(LPCTSTR)"windows", SMTO_NORMAL, 1000, NULL); } // If Windoows NT, use the SetDefaultPrinter API for Windows 2000, // or WriteProfileString for version 4.0 and earlier... else if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) { #if(WINVER >= 0x0500) if (osv.dwMajorVersion >= 5) // Windows 2000 or later... { bFlag = SetDefaultPrinter(pPrinterName); if (!bFlag) *Result = 0; return S_FALSE; } else // NT4.0 or earlier... #endif { // Open this printer so you can get information about it... bFlag = OpenPrinter((char*)OLE2CA(pPrinterName), &hPrinter, NULL); if (!bFlag || !hPrinter) *Result = 0; return S_FALSE; // The first GetPrinter() tells you how big our buffer should // be in order to hold ALL of PRINTER_INFO_2. Note that this will // usually return FALSE. This only means that the buffer (the 3rd // parameter) was not filled in. You don't want it filled in here... GetPrinter(hPrinter, 2, 0, 0, &dwNeeded); if (dwNeeded == 0) { ClosePrinter(hPrinter); *Result = 0; return S_FALSE; } // Allocate enough space for PRINTER_INFO_2... ppi2 = (PRINTER_INFO_2 *)GlobalAlloc(GPTR, dwNeeded); if (!ppi2) { ClosePrinter(hPrinter); *Result = 0; return S_FALSE; } // The second GetPrinter() fills in all the current // information... bFlag = GetPrinter(hPrinter, 2, (LPBYTE)ppi2, dwNeeded, &dwNeeded); if ((!bFlag) || (!ppi2->pDriverName) || (!ppi2->pPortName)) { ClosePrinter(hPrinter); GlobalFree(ppi2); *Result = 0; return S_FALSE; } // Allocate buffer big enough for concatenated string. // String will be in form "printername,drivername,portname"... pBuffer = (LPTSTR)GlobalAlloc(GPTR, lstrlen((char*)OLE2CA(pPrinterName)) + lstrlen(ppi2->pDriverName) + lstrlen(ppi2->pPortName) + 3); if (!pBuffer) { ClosePrinter(hPrinter); GlobalFree(ppi2); *Result = 0; return S_FALSE; } // Build string in form "printername,drivername,portname"... lstrcpy(pBuffer, (char*)OLE2CA(pPrinterName)); lstrcat (pBuffer, ","); lstrcat(pBuffer, ppi2->pDriverName); lstrcat(pBuffer, ","); lstrcat(pBuffer, ppi2->pPortName); // Set the default printer in Win.ini and registry... bFlag = WriteProfileString("windows", "device", pBuffer); if (!bFlag) { ClosePrinter(hPrinter); GlobalFree(ppi2); GlobalFree(pBuffer); *Result = 0; return S_FALSE; } } // Tell all open applications that this change occurred. // Allow each app 1 second to handle this message. lResult = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0L, 0L, SMTO_NORMAL, 1000, NULL); } // Cleanup... if (hPrinter) ClosePrinter(hPrinter); if (ppi2) GlobalFree(ppi2); if (pBuffer) GlobalFree(pBuffer); *Result = 1; return S_OK; }

Installation

* On each machine where you want to use the SetPrinter component, you must register the DLL as follows: regsvr32 ...

Read article at Internet.com site

Featured Local Company

design barcode label

0019800000000
Lane
City, FL

Regional Articles
- Function to Set Default Printer Altamonte Springs FL
- Function to Set Default Printer Apopka FL
- Function to Set Default Printer Arcadia FL
- Function to Set Default Printer Atlantic Beach FL
- Function to Set Default Printer Auburndale FL
- Function to Set Default Printer Avon Park FL
- Function to Set Default Printer Bartow FL
- Function to Set Default Printer Belle Glade FL
- Function to Set Default Printer Boca Raton FL
- Function to Set Default Printer Bonita Springs FL
- Function to Set Default Printer Boynton Beach FL
- Function to Set Default Printer Bradenton FL
- Function to Set Default Printer Brandon FL
- Function to Set Default Printer Brooksville FL
- Function to Set Default Printer Cantonment FL
- Function to Set Default Printer Cape Coral FL
- Function to Set Default Printer Casselberry FL
- Function to Set Default Printer Chipley FL
- Function to Set Default Printer Clearwater FL
- Function to Set Default Printer Clermont FL
- Function to Set Default Printer Clewiston FL
- Function to Set Default Printer Cocoa Beach FL
- Function to Set Default Printer Cocoa FL
- Function to Set Default Printer Crawfordville FL
- Function to Set Default Printer Crestview FL
- Function to Set Default Printer Crystal River FL
- Function to Set Default Printer Dade City FL
- Function to Set Default Printer Dania FL
- Function to Set Default Printer Daytona Beach FL
- Function to Set Default Printer Debary FL
- Function to Set Default Printer Deerfield Beach FL
- Function to Set Default Printer Defuniak Springs FL
- Function to Set Default Printer Deland FL
- Function to Set Default Printer Delray Beach FL
- Function to Set Default Printer Deltona FL
- Function to Set Default Printer Destin FL
- Function to Set Default Printer Dunedin FL
- Function to Set Default Printer Dunnellon FL
- Function to Set Default Printer Englewood FL
- Function to Set Default Printer Eustis FL
- Function to Set Default Printer Fernandina Beach FL
- Function to Set Default Printer Fort Lauderdale FL
- Function to Set Default Printer Fort Myers FL
- Function to Set Default Printer Fort Pierce FL
- Function to Set Default Printer Fort Walton Beach FL
- Function to Set Default Printer Gainesville FL
- Function to Set Default Printer Green Cove Springs FL
- Function to Set Default Printer Gulf Breeze FL
- Function to Set Default Printer Haines City FL
- Function to Set Default Printer Hallandale FL
- Function to Set Default Printer Hialeah FL
- Function to Set Default Printer Hobe Sound FL
- Function to Set Default Printer Holiday FL
- Function to Set Default Printer Hollywood FL
- Function to Set Default Printer Homestead FL
- Function to Set Default Printer Homosassa FL
- Function to Set Default Printer Hudson FL
- Function to Set Default Printer Immokalee FL
- Function to Set Default Printer Inverness FL
- Function to Set Default Printer Jacksonville Beach FL
- Function to Set Default Printer Jacksonville FL
- Function to Set Default Printer Jensen Beach FL
- Function to Set Default Printer Jupiter FL
- Function to Set Default Printer Key West FL
- Function to Set Default Printer Kissimmee FL
- Function to Set Default Printer Labelle FL
- Function to Set Default Printer Lady Lake FL
- Function to Set Default Printer Lake City FL
- Function to Set Default Printer Lake Mary FL
- Function to Set Default Printer Lake Placid FL
- Function to Set Default Printer Lake Wales FL
- Function to Set Default Printer Lake Worth FL
- Function to Set Default Printer Lakeland FL
- Function to Set Default Printer Land O Lakes FL
- Function to Set Default Printer Largo FL
- Function to Set Default Printer Leesburg FL
- Function to Set Default Printer Lehigh Acres FL
- Function to Set Default Printer Live Oak FL
- Function to Set Default Printer Longwood FL
- Function to Set Default Printer Loxahatchee FL
- Function to Set Default Printer Lutz FL
- Function to Set Default Printer Lynn Haven FL
- Function to Set Default Printer Marco Island FL
- Function to Set Default Printer Marianna FL
- Function to Set Default Printer Melbourne FL
- Function to Set Default Printer Merritt Island FL
- Function to Set Default Printer Miami Beach FL
- Function to Set Default Printer Miami FL
- Function to Set Default Printer Miami Lakes FL
- Function to Set Default Printer Middleburg FL
- Function to Set Default Printer Milton FL
- Function to Set Default Printer Miramar FL
- Function to Set Default Printer Mount Dora FL
- Function to Set Default Printer Mulberry FL
- Function to Set Default Printer Naples FL
- Function to Set Default Printer Navarre FL
- Function to Set Default Printer New Port Richey FL
- Function to Set Default Printer New Smyrna Beach FL
- Function to Set Default Printer Niceville FL
- Function to Set Default Printer Nokomis FL
- Function to Set Default Printer North Fort Myers FL
- Function to Set Default Printer North Miami Beach FL
- Function to Set Default Printer North Palm Beach FL
- Function to Set Default Printer North Port FL
- Function to Set Default Printer Ocala FL
- Function to Set Default Printer Ocoee FL
- Function to Set Default Printer Okeechobee FL
- Function to Set Default Printer Oldsmar FL
- Function to Set Default Printer Opa Locka FL
- Function to Set Default Printer Orange City FL
- Function to Set Default Printer Orange Park FL
- Function to Set Default Printer Orlando FL
- Function to Set Default Printer Ormond Beach FL
- Function to Set Default Printer Oviedo FL
- Function to Set Default Printer Palatka FL
- Function to Set Default Printer Palm Bay FL
- Function to Set Default Printer Palm Beach FL
- Function to Set Default Printer Palm Beach Gardens FL
- Function to Set Default Printer Palm City FL
- Function to Set Default Printer Palm Coast FL
- Function to Set Default Printer Palm Harbor FL
- Function to Set Default Printer Palmetto FL
- Function to Set Default Printer Panama City Beach FL
- Function to Set Default Printer Panama City FL
- Function to Set Default Printer Pembroke Pines FL
- Function to Set Default Printer Pensacola FL
- Function to Set Default Printer Pinellas Park FL
- Function to Set Default Printer Plant City FL
- Function to Set Default Printer Pompano Beach FL
- Function to Set Default Printer Ponte Vedra Beach FL
- Function to Set Default Printer Port Charlotte FL
- Function to Set Default Printer Port Orange FL
- Function to Set Default Printer Port Richey FL
- Function to Set Default Printer Port Saint Lucie FL
- Function to Set Default Printer Punta Gorda FL
- Function to Set Default Printer Riverview FL
- Function to Set Default Printer Rockledge FL
- Function to Set Default Printer Safety Harbor FL
- Function to Set Default Printer Saint Augustine FL
- Function to Set Default Printer Saint Cloud FL
- Function to Set Default Printer Saint Petersburg FL
- Function to Set Default Printer Sanford FL
- Function to Set Default Printer Sarasota FL
- Function to Set Default Printer Satellite Beach FL
- Function to Set Default Printer Sebastian FL
- Function to Set Default Printer Sebring FL
- Function to Set Default Printer Seffner FL
- Function to Set Default Printer Seminole FL
- Function to Set Default Printer Spring Hill FL
- Function to Set Default Printer Starke FL
- Function to Set Default Printer Stuart FL
- Function to Set Default Printer Summerfield FL
- Function to Set Default Printer Sun City Center FL
- Function to Set Default Printer Tallahassee FL
- Function to Set Default Printer Tampa FL
- Function to Set Default Printer Tarpon Springs FL
- Function to Set Default Printer Titusville FL
- Function to Set Default Printer Valrico FL
- Function to Set Default Printer Venice FL
- Function to Set Default Printer Vero Beach FL
- Function to Set Default Printer Wauchula FL
- Function to Set Default Printer Wesley Chapel FL
- Function to Set Default Printer West Palm Beach FL
- Function to Set Default Printer Winter Garden FL
- Function to Set Default Printer Winter Haven FL
- Function to Set Default Printer Winter Park FL
- Function to Set Default Printer Winter Springs FL
- Function to Set Default Printer Zephyrhills FL
Related Local Events
Wednesday Evening Referral Group
Dates: 5/5/2010 - 5/7/2010
Location: WineStyles
Coral Springs, FL
View Details

Wake Up Coral Springs Breakfast!!
Dates: 6/15/2010 - 6/15/2010
Location: Marriott Heron Bay
Coral Springs, FL
View Details

Afternoon Chamber Referral Group
Dates: 7/1/2010 - 7/1/2010
Location: The Coral Springs Chamber Office
Coral Springs, FL
View Details

Morning Chamber Referral Group Meeting
Dates: 7/22/2010 - 7/22/2010
Location: La Quinta Hotel
Coral Springs, FL
View Details

Business Development Committee Meeting TIME CHANGED
Dates: 7/27/2010 - 7/27/2010
Location: St. Lucie County Chamber of Commerce
Port St. Lucie, FL
View Details

Topics: 
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML