好吧,我真的需要一些帮助,在这里!我不是最好的C程序员那里,但我通常可以找到我的方式通过。但是,这可难倒我了。我工作的公司已经使用的开放源码程序打印PDF文件,从约6年的会计软件。该方案最初是在V $ C + + 6.0编写。在居留权的infinate wisdome的现在,他们决定改变; 10.X被释放时的程序中使用的函数的名称。 (我理解他们的理由,但是......)我发现和下载程序,我导入一个VS 2005 C项目的程序。我可以修改它与Adobe 10.X工作,但它不会工作; 9.x或以下。我做了一些研究,发现了Adobe在Windows注册表中添加应用程序的名称,所以我不得不这样做是读取注册表项,并用它做。现在这方面的工作后2天,我很沮丧,我不能得到这个程序编译。我不知道我错过任何帮助将不胜感激!在下面的代码,你可以搜索"adobeversion",你可以看到我想要做什么。我试图使用RegistryKey类,但我得到的编译错误。我知道这是漫长的,但我认为这将是更好地看到整个程序。
再次提前感谢!
#include <windows.h>
#include <ddeml.h>
#include <string.h>
#include <stdio.h>
#include "PrinterUtils.h"
#define TIMEOUT 60
int multiplier=1;
HWND hWndAdobe=0;
BOOL isRunning=FALSE;
BOOL wasRunning=TRUE;
char* adobeversion=" ";
//char szAdobe[MAX_PATH];
//HKEY hKey=0;
//char regbuf[255]="";
//DWORD dwType=0;
//DWORD dwBufSize=sizeof(regbuf);
const char* subkey="acrobat\\shell\\open\\ddeexec\\application";
// Try to find the version of Adobe installed on the workstation
/*char getPDFVersion()
{
if( RegOpenKey(HKEY_CLASSES_ROOT, subkey, &hKey) == ERROR_SUCCESS)
{
dwType = REG_SZ;
if ( RegQueryValueEx(hKey, "(Default)", 0, &dwType, (BYTE*)regbuf, &dwBufSize) == ERROR_SUCCESS)
{
return 1;
}
else
{
return 0;
}
}
else
{
return 0;
}
} */
// Hide Adobe Window
// Adobe Reader 7 always pops up when printing, ignores SW_HIDE, so hide it offscreen
void HideAdobe()
{
ShowWindow (hWndAdobe, SW_RESTORE);
MoveWindow (hWndAdobe, -100, -100, 0, 0, TRUE);
ShowWindow (hWndAdobe, SW_RESTORE);
}
// Determine if Acrobat or Reader is running
BOOL isAdobeRunning()
{
// Search all windows for title starting with szWnd
// hWndAdobe = FindWindow("AdobeAcrobat", NULL);
hWndAdobe = FindWindow(NULL, "Adobe Reader");
isRunning = (hWndAdobe > 0 ? TRUE: FALSE);
return(isRunning);
}
void usage(char *p)
{
printf("usage:\t%s [options] [drive:][path]<filename>\n", p);
printf("specifies drive, directory, and/or file(s) to print.\n");
printf("prints to default printer unless [printer] specified.\n\n");
printf("options:\n");
printf("\t-p printer : print to specified printer (must be first option)\n");
printf("\t\tSpecify complete printer UNC name for network printers:\n");
printf("\t\t\t\"\\\\printserver\\printer\"\n");
printf("\t\t\tsurround with double-quotes if any spaces in printer name\n\n");
printf("\t-o orientation : set orientation\n");
printf("\t\t1=portrait, 2=landscape\n\n");
printf("\t-d duplex : set duplex mode (if supported by printer)\n");
printf("\t\t1=none, 2=long side, 3=short side\n\n");
printf("\t-c copies : set number of copies to print\n");
printf("\t\tcopies=1 to 10\n");
exit(0);
}
// Callback function for DDE messages
HDDEDATA CALLBACK DDECallback( UINT wType,
UINT wFmt,
HCONV hConv,
HSZ hsz1,
HSZ hsz2,
HDDEDATA hDDEData,
DWORD dwData1,
DWORD dwData2)
{
switch (wType) {
default:
return NULL;
break;
}
}
// Send a DDE execute request to Acrobat/Reader
static BOOL SendExecCmd(LPSTR lpszCmd)
{
int test=0;
DWORD dwDDEInst = 0;
UINT ui;
HSZ hszApplication;
HSZ hszTopic;
HCONV hConv;
HDDEDATA hExecData;
// Initialize DDEML
ui = DdeInitialize(&dwDDEInst,
DDECallback,
CBF_FAIL_ALLSVRXACTIONS,
0l);
if (ui != DMLERR_NO_ERROR) {
return FALSE;
}
// Initiate a conversation with the acroview application
// on the control topic.
/* Jim Whalen - 11-10-2011 The release of Reader 10.X does not work with this application
Found we need to change the commad acroview to acroviewR10
*/
/* hszApplication = DdeCreateStringHandle( dwDDEInst,
"acroview",
CP_WINANSI);
*/
//test=getPDFVersion();
//if (test != 1)
// return FALSE;
RegistryKey reg = (Registry.ClassesRoot).OpenSubKey(subkey);
adobeversion = reg.GetValue("(Default)");
hszApplication = DdeCreateStringHandle( dwDDEInst,
adobeversion,
CP_WINANSI);
hszTopic = DdeCreateStringHandle(dwDDEInst,
"control",
CP_WINANSI);
hConv = DdeConnect(dwDDEInst,
hszApplication,
hszTopic,
NULL);
// Free the HSZ now
DdeFreeStringHandle(dwDDEInst, hszApplication);
DdeFreeStringHandle(dwDDEInst, hszTopic);
if (!hConv) {
return FALSE;
}
// Create a data handle for the exec string
hExecData = DdeCreateDataHandle(dwDDEInst,
lpszCmd,
lstrlen(lpszCmd)+1,
0,
NULL,
0,
0);
// Send the execute request
DdeClientTransaction( (void FAR *)hExecData,
(DWORD)-1,
hConv,
NULL,
0,
XTYP_EXECUTE,
TIMEOUT * 1000 * multiplier, // ms timeout
NULL);
// Done with the conversation now.
DdeDisconnect(hConv);
// Done with DDEML
DdeUninitialize(dwDDEInst);
return TRUE;
}
BOOL pdfprint(LPSTR lpszPath, LPSTR lpszPrinter, LPSTR lpszPort, LPSTR lpszDriver)
{
char buf[2048];
int i;
BOOL ret;
FILE *f;
long lSize;
// Find the file's length
f = fopen(lpszPath, "r");
if(f == NULL)
return 0;
fseek(f,0,SEEK_END);
lSize=ftell(f);
fclose(f);
// Extend the timeout for each MB of filesize
multiplier = (int)(lSize / 1000000)+1;
if(lpszPath && lstrlen(lpszPath)) {
if(lpszPrinter && lstrlen(lpszPrinter))
{
sprintf(buf,
"[FilePrintTo(\"%s\",%s,\"%s\",\"%s\")]",
lpszPath, lpszPrinter, lpszDriver, lpszPort);
}
else
{
sprintf(buf,
"[FilePrintSilent(\"%s\")]",
lpszPath);
}
}
printf("Printing: %s\n", lpszPath);
for(i=0;i<3;i++)
{
HideAdobe();
ret = SendExecCmd(buf);
if(ret)
break;
Sleep(1000);
}
//HideAdobe();
return(ret);
}
int main(int argc, char* argv[])
{
char szPrinter[MAX_PATH];
char szPrinterName[MAX_PATH];
char szPort[MAX_PATH];
char szDriver[MAX_PATH];
char szFile[MAX_PATH];
char szPath[MAX_PATH];
char *p;
int i;
int s=1;
int nPrinted=0;
int val=0;
HANDLE hPrinter=0;
WIN32_FIND_DATA find_data;
HANDLE hFind;
PRINTER_INFO_2 *ppi2 = NULL;
LPDEVMODE pDevMode1 = NULL;
LPDEVMODE pDevMode2 = NULL;
BOOL bSetProperties = FALSE;
DWORD dwNeeded = 0;
BOOL bFlag;
char *pattern;
BOOL bFirst = TRUE;
LPTSTR lpFilePart;
DWORD dwStatus;
if (argc < 2)
{
usage(argv[0]);
return 0;
}
*szPrinter='\0';
*szPrinterName='\0';
// Get default printer name
GetDefaultPrinterName(szPrinterName, sizeof(szPrinterName));
// Get default printer settings
pDevMode1 = GetPrinterDevMode(szPrinterName);
pDevMode2 = GetPrinterDevMode(szPrinterName);
for(i=1;i<argc;i++)>
{
p = argv[i];
if(*p == '-')
{
if(++i >= argc)
usage(argv[0]);
switch (*(++p)) {
case 'p' :
if(i != 2) {
// -p must be first option, if used
printf("-p MUST be first option, if used\n");
usage(argv[0]);
}
strcpy(szPrinter, argv[i]);
// Make sure printer name is valid
if(OpenPrinter(szPrinter, &hPrinter, NULL)==0)
{
// If not valid, return
printf("Printer not found: '%s'\n", szPrinter);
return 1;
}
// Find out how much space is needed
GetPrinter(hPrinter, 2, 0, 0, &dwNeeded);
if (dwNeeded ==