I apologize for my lack of knowledge but that's why i'm here. I am a .net developer don't all boo and hiss... :-) but am working on a project with MS Host Integration Server and printing. Within HIS you can define print filter DLLs (must be C++) that allow you to append data to the print stream:
http://msdn.microsoft.com/en-us/library/gg164794.aspx I have been able to compile the example (slightly modified) in VS2012 for a 32bit architecture but our target platform in x64 and when I try to compile it as best i know how for 64 bit I get an warning C4090: 'function' : different '__unaligned' qualifiers C:\Program Files (x86)\Windows Kits\8.0\Include\shared\stralign.h and now am clueless....
The dll is really simple see code below but i fear my lack of knowledge on how to compile this correctly is causing the problems, I will also make it even simpler when i take out all the trace code, but will leave it in for the time being to help me work out whats going on.
Any assistance will be gratefully received. Thanks in advance. Steve
---NTFilter.h---
#include <windows.h>
#include <stdio.h>
#define SIZEBUF 4096
__declspec( dllexport ) void * WINAPI PrtFilterAlloc(DWORD Buflen);
__declspec( dllexport ) void WINAPI PrtFilterFree(void *pBuf);
__declspec( dllexport ) void * WINAPI PrtFilterJobStart(char *SessionName,DWORD LUType,char** pBufPtr,DWORD *pBuflen);
__declspec( dllexport ) void WINAPI PrtFilterJobData(void *UniqueID, char **pBufPtr,DWORD *pBufLen);
__declspec( dllexport ) void * WINAPI PrtFilterJobEnd(char *SessionName,char** pBufPtr,DWORD *pBuflen);
BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved );
void trace(char *text);
-------
---NTFilter.c---
/*
/* NtFilter.c
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* This sample illustrates using the Host Integration Server
* print filter APIs
*
*/
#include "NtFilter.h"
int SessId =156789;
void * Uid = (void *)&SessId ;
FILE *f;
BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved )
{
switch( ul_reason_for_call )
{
case DLL_PROCESS_ATTACH:
trace("Initialization - Process Attach");
break;
case DLL_THREAD_ATTACH:
trace("Thread Attach");
break;
case DLL_THREAD_DETACH:
trace("Thread Detach");
break;
case DLL_PROCESS_DETACH:
trace("Process Detach");
break;
}
return TRUE;
}
__declspec( dllexport ) void * WINAPI PrtFilterAlloc(DWORD BufLen)
{
/* MSFT - 3 lines for Debug OutPut - START */
void * pBuf ;
char TrBuf[50] ;
trace("FilterAlloc");
/* MSFT - 3 lines for Debug OutPut - END */
pBuf = malloc(BufLen) ;
/* MSFT - 2 lines for Debug OutPut - START */
sprintf_s (TrBuf, _countof(TrBuf), "%x ",pBuf);
trace (TrBuf) ;
/* MSFT - 2 lines for Debug OutPut - END */
return(pBuf);
}
__declspec( dllexport ) void WINAPI PrtFilterFree(void *pBuf)
{
/* MSFT - 4 lines for Debug OutPut - START */
char TrBuf[50] ;
trace("FilterFree");
sprintf_s (TrBuf,_countof(TrBuf), "%x ",pBuf);
trace (TrBuf) ;
/* MSFT - 4 lines for Debug OutPut - END */
free(pBuf);
/* MSFT - 1 line for Debug OutPut - START */
trace(" Buffer library");
/* MSFT - 1 line for Debug OutPut - END */
return;
}
__declspec( dllexport ) void WINAPI PrtFilterJobData(void *UniqueID, char **pBufPtr,DWORD *pBufLen)
{
/* MSFT - 4 lines for Debug OutPut - START */
char TrBuf[50] ;
trace("FilterJobData");
sprintf_s (TrBuf, _countof(TrBuf), "%d ",*pBufLen);
trace (TrBuf) ;
/* MSFT - 4 lines for Debug OutPut - END */
return;
}
__declspec( dllexport ) void * WINAPI PrtFilterJobStart(char *SessionName, DWORD LUType, char** pBufPtr, DWORD *pBufLen)
{
/* MSFT - 1 line for Debug OutPut - START */
trace("FilterJobStart");
/* MSFT - 1 line for Debug OutPut - END */
strcpy_s(*pBufPtr, 2, "-|" );
strcpy_s(*pBufPtr, _countof(pBufPtr), SessionName );
strcpy_s(*pBufPtr, 2, "|-" );
*pBufLen=(DWORD)strlen(*pBufPtr);
return((void *)(Uid));
}
__declspec( dllexport ) void * WINAPI PrtFilterJobEnd(char *SessionName,char** pBufPtr,DWORD *pBufLen)
{
/* MSFT - 1 line for Debug OutPut - START */
trace("FilterJobEnd");
/* MSFT - 1 line for Debug OutPut - END */
return((void *)(Uid));
}
void trace(char *text)
{
errno_t err;
err = fopen_s ( &f, "c:\\trfilter.txt","a+t");
fprintf(f,"NTFILTER : %s \n",text);
fclose(f);
}
--------