Porting MyPDFCreator to x64 bit

 Hi,

 
Request:
I am using the PDFCreator source code and have customized it a lot. So far my installer for installing my 
 
pdfcreator ran perfectly on 32bit OSs. but it doesnt work on 64bit OS. I installed PDFCreator 0.9.9 on the 
 
same 64 bit machine and it installed fine. I need those changes done to PDFCreator to make my pdfcreator work 
 
for x64 too. 
 
situation:
-Monitor installed successfully by changing Enviroment to "Window x64" and using x64 bit version of 
 
redmon.dll.
-Port also installed fine.
-Adding driver is failing for some reason. upon success all below files should be copied to DriverDir\\3\\ 
 
folder with a new .bpd file. but the .bpd file is no there. 
-consequently, adding printer is also failing as it depends on the previous step.
 
Currently my installer Puts the driver files in DriverDir:
%sys%\\spool\\driver\\x64\\
 
Files:
- mypdfcreator.ppd
- mypdfcreator.dll   32 bit dll
- ps5ui.dll          32 bit dll      
- pscript.ntf
- pscript.hlp
- pscript5.dll       32 bit dll
 
what versions of these files will i need or changes to code will i require to make it work on 64 bit os. And 
 
what special registry entries might be required. 
 
I have already tried placing the dlls in different locations, like the monitor only installed successfully 
 
when pdfcmnnt.dll is placed in System32 instead of SysWOW64 folder. I also tried recompiling mypdfcreator.dll 
 
to x64 target, and messed with files and tried using PDFCreator's version of other files but still no success.
 
Kindly, tell me what should be the version or bitness (x32 or x64) and location of each file for the process 
 
to be successful on x64. Thanks in advance.

Hello,

that is a bit tricky, but basically you seem on the right way - can you give us a source tarball and details on what you did, so we can have a look at it?

kind regards,
Philip

 

I couldnt find any option to attach my files with this reply, so i am just posting my source code. This code installs printer. The files PScript5.dll, pscript.hlp are same as PDFCreator after installation. .PPD and .ntf files are my old files. MyPDFCreator.dll, the config file used for PrinterDriver is my own file compiled to x64 bit. Please, let me know if u need anything else. Thanks

void InstallPrinter(CString szApplicationPath) { USES_CONVERSION;

//"INFO - Installing the Printer Monitor");
InstallMonitor();

// "INFO - Installing the Printer Port");
InstallPort();

// "INFO - Installing the Printer Driver");
InstallPrinterDriver();

// "INFO - Updating the PrintSpooler service info base");
AddPrinterInfo();	

}

void InstallMonitor()
{
MONITOR_INFO_2 MI;

MI.pName = MY_PRINTER_MONITOR_NAME;
if(IsWindowsNT() == TRUE)
{
if( is64bitWindows() )
{
MI.pEnvironment = _T(“Windows x64”);
}
else
{
MI.pEnvironment = _T(“Windows NT x86”);
}

	MI.pDLLName = _T("pdfcmnnt.dll");
}
else
{
	MI.pEnvironment = _T("Windows 4.0");
	MI.pDLLName = _T("pdfcmn95.dll");
}
	
BOOL bRet = AddMonitor(NULL, 2, (LPBYTE)&MI);
if(!bRet)
{
	CString szErrorDescription(GetErrorDescription(GetLastError()).c_str());

AfxMessageBox(_T("Error occurred while installing printer monitor. Reason: “) + str + _T(”
") + szErrorDescription );
}
}

void InstallPort()
{
CRegKey regKey;
if(regKey.Open(HKEY_LOCAL_MACHINE, _T(“System\\CurrentControlSet\\Control\\Print\\Monitors”)) != ERROR_SUCCESS)
return;

CString szKeyToBeCreated = _T("MyPDFCreator\\\\Ports\\\\MyPDFPort:");
CRegKey regPrinter;
if(regPrinter.Create(regKey.m_hKey, szKeyToBeCreated) != ERROR_SUCCESS)
{
	regKey.Close();
	return;
}

TCHAR tcPDFSpooler_EXE[MAX_PATH] = {0};
GetSystemDirectory(tcPDFSpooler_EXE, MAX_PATH);
StrCatW(tcPDFSpooler_EXE, _T("\\\\PDFSpooler.exe") );	
	
regPrinter.SetStringValue(_T("Arguments"), _T("-PPDFCONVERTERPRINTER"));

regPrinter.SetStringValue(_T(“Command”), tcPDFSpooler_EXE );
regPrinter.SetDWORDValue(_T(“Delay”), 300);
regPrinter.SetStringValue(_T(“Description”), _T(“My PDF Redirected Port”));
regPrinter.SetDWORDValue(_T(“LogFileDebug”), 0);
regPrinter.SetStringValue(_T(“LogFileName”), _T(""));
regPrinter.SetDWORDValue(_T(“LogFileUse”), 0);
regPrinter.SetDWORDValue(_T(“Output”), 0);
regPrinter.SetStringValue(_T(“Printer”), _T(“MyPDFCreator”));
regPrinter.SetDWORDValue(_T(“PrintError”), 0);
regPrinter.SetDWORDValue(_T(“RunUser”), 0);
regPrinter.SetDWORDValue(_T(“ShowWindow”), 0);

CRegKey regPort;
CString szPortKey = _T("System\\\\CurrentControlSet\\\\Control\\\\Print\\\\Ports\\\\MyPDFPort:");
if(regPort.Create(HKEY_LOCAL_MACHINE, szPortKey) != ERROR_SUCCESS)
{
	regKey.Close();
	regPrinter.Close();
	return;
}
regKey.Close();
regPrinter.Close();
regPort.Close();

}

void InstallPrinterDriver()
{
USES_CONVERSION;

DWORD dwLengthRequired, dwLengthConsumed;

GetPrinterDriverDirectory(NULL, NULL, 1, NULL, 0, &dwLengthRequired);

TCHAR * tcPrinterDriverDirectory = new TCHAR[dwLengthRequired];
dwLengthConsumed = dwLengthRequired;

GetPrinterDriverDirectory(NULL, NULL, 1, (LPBYTE)tcPrinterDriverDirectory, dwLengthConsumed, &dwLengthRequired);

CString szPrinterDriverDirectory = tcPrinterDriverDirectory;
szPrinterDriverDirectory += _T("\\\");
delete tcPrinterDriverDirectory;

DRIVER_INFO_3 DI3;
ZeroMemory(&DI3, sizeof(DI3));

DI3.pName = _T("MyPDFDriver");

TCHAR tcPSCRIPT_NTF[MAX_PATH] = {0};
TCHAR tcMyPDFDriver_DLL[MAX_PATH] = {0};
TCHAR tcPSCRIPT5_DLL[MAX_PATH] = {0};
TCHAR tcPSCRIPT_HLP[MAX_PATH] = {0};
TCHAR tcMyPDFConverter_PPD[MAX_PATH] = {0};
TCHAR tcMonitorName[MAX_PATH] = {0};

StrCpyW(tcPSCRIPT_NTF, szPrinterDriverDirectory + _T("PSCRIPT.NTF"));
StrCpyW(tcMyPDFDriver_DLL, szPrinterDriverDirectory + _T("MyPDFDriver.dll"));
StrCpyW(tcPSCRIPT5_DLL, szPrinterDriverDirectory + _T("PSCRIPT5.DLL"));
StrCpyW(tcPSCRIPT_HLP, szPrinterDriverDirectory + _T("PSCRIPT.HLP"));
StrCpyW(tcMyPDFCreator_PPD, szPrinterDriverDirectory + _T("MyPDFCreator.PPD"));

DI3.cVersion = 3;

DI3.pDependentFiles = tcPSCRIPT_NTF;
DI3.pConfigFile = tcAscPDFDriver_DLL;
DI3.pDriverPath = tcPSCRIPT5_DLL;

if( is64bitWindows() )
{
	DI3.pEnvironment = _T("Windows x64");
}
else
	DI3.pEnvironment = _T("Windows NT x86");

DI3.pHelpFile = tcPSCRIPT_HLP;
DI3.pDataFile = tcMyPDFCreator_PPD;
DI3.pMonitorName = MY_PRINTER_MONITOR_NAME; 
DI3.pDefaultDataType = _T("RAW");

BOOL bRet = AddPrinterDriverEx(NULL, 3, (LPBYTE)&DI3, APD_COPY_ALL_FILES);
if(!bRet)
{
	CString szErrorDescription(GetErrorDescription(GetLastError()).c_str());
	AfxMessageBox(_T("Error occurred while installing the printer driver. Reason: \

“) + szPrinterDriverDirectory + _T(”
") + szErrorDescription);
}
}

void CPrinterManager::AddPrinterInfo()
{
BOOL bRet = AddPort(NULL, 0, _T(“MyPDFPort:”));

PRINTER_INFO_2 PI2;
ZeroMemory(&PI2, sizeof(PI2));

PI2.pPrinterName = _T("My PDFCreator");
PI2.pServerName = NULL;
PI2.pPortName = _T("MyPDFPort:");
PI2.pDriverName = _T("MyPDFDriver");

PI2.pLocation = _T("");
PI2.pPrintProcessor = _T(“WinPrint”);
PI2.pComment = _T(“eDoc Printer”);
PI2.pShareName = NULL;
PI2.Priority = 1;
PI2.DefaultPriority = 1;
PI2.pDatatype = _T(“RAW”);
PI2.Attributes = 0;

HANDLE hPrinter = AddPrinter(NULL, 2, (LPBYTE)&PI2);
if(!hPrinter)
{
	CString szErrorDescription(GetErrorDescription(GetLastError()).c_str());
	AfxMessageBox(_T("Error occurred while adding the printer info. Reason: ") + szErrorDescription);
}
ClosePrinter(hPrinter);

}

 

Hi,

There is no reply to my last post so i am getting worried. Please, tell me if the information i posted isnt enough, or isnt in right format. If code is required in any specific way then please let me know. I really need to solve this. Thanks