I have to develop a dll application in visual studio .net 2003 to print any file to pdf file format.I am presently using a unigraphics part file(or any other text file ) to print. With what code i have written that is when i execute a pdf file is being generated but it is empty, only a plain white sheet is present.I dont know where i am going wrong. I think there is some problem in input.I am using a printdlg function and im using GetActiveWindow() to get the handleof the present window and i am passing it in the structure.This function i am calling after UF_intialise
but if I try to create a new part in unigraphics(nx4) or after creating any simple sketch then call this handle is returning null value whereas after UF_intialise it is not null. I am attaching my code below.I think it is not able to identify which page to print.
HDC GetPrinterDC(HWND hWndParent)
// Initialize the PRINTDLG structure.
memset( &pdlg, 0, sizeof( PRINTDLG ) );
pdlg.lStructSize = sizeof( PRINTDLG );
// Set the flag to return printer DC.
pdlg.Flags = PD_RETURNDEFAULT | PD_RETURNDC;
pdlg.hwndOwner = hWndParent;
PrintDlg( &pdlg );
// hDC member of the PRINTDLG structure contains the printer DC.
void InitDocStruct( DOCINFO* di, char* docname)
// Always zero it before using it.
memset( di, 0, sizeof( DOCINFO ) );
// Fill in the required members.
di->cbSize = sizeof( DOCINFO );
di->lpszDocName = "test";
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
hInstance = (HINSTANCE)hModule;
extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
int nErr = 0;
HWND hWnd = NULL;
nErr = UF_initialize();
if (nErr != 0)
uc1601 ("Failed to initialise UG session", 1);
hWnd = GetActiveWindow();
if (hWnd != NULL)
hDC = GetPrinterDC(hWnd);
MessageBox(NULL, "Error creating DC", "Error",
MB_APPLMODAL | MB_OK );
InitDocStruct( &di, "Test");
StartDoc( hDC, &di );
StartPage( hDC );
EndPage( hDC );
EndDoc( hDC );
DeleteDC( hDC );
nErr = UF_terminate();