![]() ![]() /****** Beginning of sample code WTXSAMP2.C **************************************/ /************************************************************************/ /* Synapse Communications Technical Note */ /* WTXSAMP2.C -- January 28, 1996 */ /* */ /* A piece of sample code to clarify the technote File Transfer */ /* PROGRAM */ /************************************************************************/ #include "windows.h" #include "memory.h" #include "stdio.h" // Globals #define gAPPLNAME "WTSample" #define eXfr_APIXLAT 0x4050 #define eXfr_NOMEMRY 0x4061 unsigned int gRETURN; unsigned char gMSG[120]; unsigned char gERRORINFO[255]; HANDLE gHDLL; LRESULT CALLBACK fWndProc(HWND, unsigned int, WPARAM, LPARAM); void PASCAL fSetupAPIError(HWND ,int); int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS vWndClass; unsigned int vPVal; unsigned int vRVal; unsigned int vType; unsigned int vErrCode; unsigned char vExec[120]; BOOL vBeg, vEnd, vPgm, vErr; MSG vMsg; // Variables we'll reference are now defined, so let's get started. // First, we'll build a window so that we will be able to get messages // from the WinTran program. We don't have to show the window -- in // fact, we won't. memset(&vWndClass,0,sizeof(WNDCLASS)); vWndClass.lpfnWndProc = fWndProc; vWndClass.hInstance = hInstance; vWndClass.hCursor = LoadCursor(NULL, IDC_ARROW); vWndClass.lpszClassName = "WTSAMPLE"; gRETURN = RegisterClass (&vWndClass); if (gRETURN == 0) { // Error in Registering Class MessageBeep(0); MessageBox(NULL, "RegisterClass! - ERROR", gAPPLNAME, MB_OK | MB_ICONSTOP); return(TRUE); } gHDLL = CreateWindow("WTSAMPLE",NULL,WS_POPUP,1,1,1,1,NULL,NULL,hInstance,NULL); if (gHDLL == 0) { // Error in Creating Window MessageBeep(0); MessageBox(NULL, "CreateWindow! - ERROR", gAPPLNAME, MB_OK | MB_ICONSTOP); return(TRUE); } // This is the value we'll use with the command line "/P" option // to identify OUR messages from the file transfer program. This // value will also appear as the first 4 characters in our entries // in the log file. vPVal=1000; // This is a number to add to the Request Name the so that the program may loop thru // and add 1 to this number and and execute different requests. vRVal=0; // Since we're going to be monitoring for messages from the file // transfer program, we must register its message type before // executing the transfer program. vType=RegisterWindowMessage("XfrPgmCtlMsg"); if (vType == 0) { // Error in Register Window Message MessageBeep(0); MessageBox(NULL, "RegisterWindowMessage! - ERROR", gAPPLNAME, MB_OK | MB_ICONSTOP); return(TRUE); } // Now we'll construct the command line. All parms are // case-insensitive. Note that we'll need to change some values // if we rename the file transfer program or its directory (or // if we ever want to execute a different transfer request file). ///////////////// ********************************************* ////////////////////////////////// // Also note that one file transfer is done before starting another one // // the program WAS written this way on purpose. If you try and WIN_EXEC multiple transfers // // they will work as long as you don't use and modal dialogues to display errors, but if you // // (like this programd does) messages WILL be lost when the dialogue is put up. // // Also this way you can write the program to do certain things if a transfer doesn't // // finish correctly. // ///////////////// ********************************************* ////////////////////////////////// Again: vPVal = vPVal + 1; // change the "/P" option that identifies OUR messages if (vRVal ==2) // if it is the third request make it a transfer to the AS/400 { // Make sure to change Path to Your location of Transfer program sprintf(vExec,"D:\\DEV\\wt32\\WT400XFR.EXE XFERREQ%0d.P2A /P%04d",vRVal,vPVal); } else // all other requests are downloads { // Make sure to change Path to Your location of Transfer program sprintf(vExec,"D:\\DEV\\wt32\\WT400XFR.EXE XFERREQ%0d.A2P /P%04d",vRVal,vPVal); } // Now We're ready to evoke the file transfer program. Let's do it. gRETURN = WinExec(vExec,SW_HIDE); if (gRETURN == ERROR_BAD_FORMAT) { // Display error message for Bad format! MessageBeep(0); MessageBox(NULL, "WinExec CMD! - BAD_FORMAT", gAPPLNAME, MB_OK | MB_ICONSTOP); return(TRUE); } if (gRETURN == ERROR_FILE_NOT_FOUND) { // Display error message for File not Found! MessageBeep(0); MessageBox(NULL, "WinExec CMD! - FILE_NOT_FOUND", gAPPLNAME, MB_OK | MB_ICONSTOP); return(TRUE); } if (gRETURN == ERROR_PATH_NOT_FOUND) { // Display error message for path not found! MessageBeep(0); MessageBox(NULL, "WinExec CMD! - PATH_NOT_FOUND", gAPPLNAME, MB_OK | MB_ICONSTOP); return(TRUE); } // Note that we set the second parameter to SW_HIDE. This is // used to circumvent WinTran's password protection, just in case. // We didn't want the transfer to hang, waiting for someone // to enter a password -- after all, we might have been started // automatically by a "scheduler" program. One other note: // 32-bit programs might use the "CreateProcess" function, instead // of "WinExec", to evoke another program. If so, the "STARTUPINFO" // structure would contain the SW_HIDE parameter. vRVal = vRVal + 1; // increment counter of number of transfers submitted // Assuming that WinExec worked, we're now going to enter our message // loop to monitor the progress of the transfer. Here we go... vBeg=vEnd=vPgm=vErr=0; // Clear our flags while (GetMessage(&vMsg,0,0,0)) // Retrieve message(s) { if (vMsg.message == vType) // A message from WinTran? { // It is!! if (vMsg.wParam == vPVal) // One of ours? { // It is, check further. if (LOWORD(vMsg.lParam) == 0) // Started Transfer? vBeg = TRUE; // Yep, set a flag if (LOWORD(vMsg.lParam) == 1) // Transfer Ended? { vEnd = TRUE; // Yep, set a flag } if (LOWORD(vMsg.lParam) == 2) // Transfer Error? { // Yep, set a flag & vErr = TRUE; // Get possible code vErrCode = (unsigned int)HIWORD(vMsg.lParam); } if (LOWORD(vMsg.lParam) == 3) // Did WinTran even start? { vPgm = TRUE; // Nope, set a flag } } } // If not a message from WinTran, just process like any other // Windows message. else { TranslateMessage(&vMsg); DispatchMessage(&vMsg); } // Now that we're done processing messages, let's check our flags. if (vBeg) // OK, the transfer started. If we were { // ambitious, we might want to start } // a timer or sumpin, just for grins. if (vEnd) // Has the transfer ended? if so { // end what was started for this tranfer and if (vRVal >= 4) // are all transfers done?, if so PostQuitMessage(0); // we can exit. else goto Again; // else do the next transfer } // also do what ever processing is required. if (vErr) // If we've encountered an error, we { // may want to do something with the fSetupAPIError(hInstance, vErrCode); // information, who knows? MessageBeep(0); MessageBox(NULL, gERRORINFO, gAPPLNAME, MB_OK | MB_ICONSTOP); if (vRVal >= 4) // are all transfers done?, if so PostQuitMessage(0); // we can exit. else goto Again; // else do the next transfer } } return(0); // Aw, someone posted a quit message. We could, of // course, still do something useful with this program } // but, instead, we'll just exit; /****************************************************************************/ /* fSetupAPIError - Get the additional error information, call error dialog*/ /****************************************************************************/ void PASCAL fSetupAPIError(HWND hInstance,int vErrCode) { int vRECORDCNT = 0; unsigned char vWRKSTR[255]; unsigned char vTEMPSTR[255]; if (vErrCode == -1) // Load No Memory error message { LoadString(hInstance,eXfr_NOMEMRY,vTEMPSTR,255); } else if (vErrCode < 256) // Error in field # (1 - 256) { LoadString(hInstance,eXfr_APIXLAT,vWRKSTR,255); sprintf(vTEMPSTR,vWRKSTR,vErrCode,vRECORDCNT); } else { LoadString(hInstance,vErrCode,vTEMPSTR,255); // Load rest of errors from string table } wsprintf((LPSTR)gERRORINFO, "Error code: x%04X\n\r%s", vErrCode, (LPSTR) vTEMPSTR); // display error code and message } // Just a minimal window procedure follows. LRESULT CALLBACK fWndProc(HWND vWnd, unsigned int iMessage, WPARAM wParam, LPARAM lParam) { return DefWindowProc (vWnd, iMessage, wParam, lParam) ; } /****** End of sample code WTXSAMP2.C **************************************/ /****** Beginning of sample code WTXSAMP2.RC *******************************/ /************************************************************************/ /* Synapse Communications Technical Note */ /* WTXSAMP2.RC -- January 28, 1996 */ /* */ /* A piece of sample code to clarify the technote WTXFER.DOC */ /* RESOURCE */ /************************************************************************/ #include "windows.h" // API and disk I/O error messages #define eXfr_API0103Msg "Internal error#0 - contact technical support." #define eXfr_API0300Msg "Untranslatable data found in transferred record." #define eXfr_API0302Msg "Untranslatable data found in transferred record." #define eXfr_API0400Msg "Warning - the AS/400 member will be overwritten." #define eXfr_API2000Msg "Maximum number of Transfer Requests are active." #define eXfr_API2001Msg "Transfer Request length length not valid." #define eXfr_API2002Msg "Transfer Request character cannot be translated." #define eXfr_API2003Msg "Untranslatable numeric data found." #define eXfr_API2004Msg "Numeric data is too large for field." #define eXfr_API2005Msg "Record length given is incorrect." #define eXfr_API2007Msg "Null map offset is incorrect" #define eXfr_API2008Msg "Total length of record exceeds 4096 bytes." #define eXfr_API2009Msg "Internal error#1 - contact technical support." #define eXfr_API2010Msg "Internal error#2 - contact technical support." #define eXfr_API2011Msg "Internal error#3 - contact technical support." #define eXfr_API2012Msg "Internal error#4 - contact technical support." #define eXfr_API2013Msg "Internal error#5 - contact technical support." #define eXfr_API2019Msg "Internal error#6 - contact technical support." #define eXfr_API2020Msg "Internal error#7 - contact technical support." #define eXfr_API2021Msg "Internal error#8 - contact technical support." #define eXfr_API2022Msg "Internal error#9 - contact technical support." #define eXfr_API2023Msg "Internal error#A - contact technical support." #define eXfr_API2024Msg "Internal error#B - contact technical support." #define eXfr_API2025Msg "Internal error#C - contact technical support." #define eXfr_API2026Msg "Internal error#D - contact technical support." #define eXfr_API2027Msg "Internal error#E - contact technical support." #define eXfr_API2028Msg "Internal error#F - contact technical support." #define eXfr_API2029Msg "PCSWIN buffer space exhausted." #define eXfr_API2030Msg "Options statement not supported on this system." #define eXfr_API3000Msg "Error detected by the host system.." #define eXfr_API3100Msg "Error detected by the host system." #define eXfr_API5042Msg "The router has not been started." #define eXfr_API5048Msg "Connection to the host system failed." #define eXfr_API5050Msg "System name is incorrect or inactive." #define eXfr_API5052Msg "System program not found." #define eXfr_API5054Msg "System program ended unexpectedly." #define eXfr_API5056Msg "Security error occurred on the host system." #define eXfr_API5058Msg "Host system is not a supported system." #define eXfr_API5060Msg "Host system is at an unsupported version, release or modification level." #define eXfr_API5062Msg "Contact with the host system ended." #define eXfr_API5066Msg "System resource failure." #define eXfr_API5067Msg "The conversation was ended unexpectedly." #define eXfr_API5071Msg "Insufficient memory." #define eXfr_API5310Msg "PCSWIN is not loaded." #define eXfr_API5311Msg "Cannot run in Windows real mode." #define eXfr_API5400Msg "Operating system error." #define eXfr_API9999Msg "Undefined Error: %0d - contact technical support." #define eXfr_APIXLATMsg "Unable to translate field %0d in record %0ld." #define eXfr_RDFOPENMsg "Error opening Source PC file." #define eXfr_RDFREADMsg "Error reading Source PC file." #define eXfr_RDFNOFDMsg "Source PC file has invalid format." #define eXfr_WDFOPENMsg "Error opening Target PC file." #define eXfr_WDFWRITMsg "Error writing Target PC file." #define eXfr_FDFOPENMsg "Error opening PC File Description File." #define eXfr_FDFWRITMsg "Error writing PC File Description File." #define eXfr_FDFREADMsg "Error reading PC File Description File." #define eXfr_FDFNOFDMsg "Not a valid PC File Description File." #define eXfr_FDNOSAVMsg "Invalid SAVE file format." #define eXfr_NOMEMRYMsg "Unable to allocate/free Windows memory." #define eXfr_TOPCWRNMsg "Warning - the target PC file will be overwritten." STRINGTABLE BEGIN 0x0104, eXfr_RDFOPENMsg 0x0105, eXfr_RDFREADMsg 0x0106, eXfr_RDFNOFDMsg 0x0107, eXfr_WDFOPENMsg 0x0108, eXfr_WDFWRITMsg 0x0109, eXfr_FDFOPENMsg 0x010A, eXfr_FDFWRITMsg 0x010B, eXfr_FDFREADMsg 0x010C, eXfr_FDFNOFDMsg 0x010D, eXfr_FDNOSAVMsg 0x4050, eXfr_APIXLATMsg 0x4061, eXfr_NOMEMRYMsg 0x0103, eXfr_API0103Msg 0x0300, eXfr_API0300Msg 0x0302, eXfr_API0302Msg 0x0400, eXfr_API0400Msg 0x2000, eXfr_API2000Msg 0x2001, eXfr_API2001Msg 0x2002, eXfr_API2002Msg 0x2003, eXfr_API2003Msg 0x2004, eXfr_API2004Msg 0x2005, eXfr_API2005Msg 0x2007, eXfr_API2007Msg 0x2008, eXfr_API2008Msg 0x2009, eXfr_API2009Msg 0x2010, eXfr_API2010Msg 0x2011, eXfr_API2011Msg 0x2012, eXfr_API2012Msg 0x2013, eXfr_API2013Msg 0x2019, eXfr_API2019Msg 0x2020, eXfr_API2020Msg 0x2021, eXfr_API2021Msg 0x2022, eXfr_API2022Msg 0x2023, eXfr_API2023Msg 0x2024, eXfr_API2024Msg 0x2025, eXfr_API2025Msg 0x2026, eXfr_API2026Msg 0x2027, eXfr_API2027Msg 0x2028, eXfr_API2028Msg 0x2029, eXfr_API2029Msg 0x2030, eXfr_API2030Msg 0x3000, eXfr_API3000Msg 0x3100, eXfr_API3100Msg 0x5042, eXfr_API5042Msg 0x5048, eXfr_API5048Msg 0x5050, eXfr_API5050Msg 0x5052, eXfr_API5052Msg 0x5054, eXfr_API5054Msg 0x5056, eXfr_API5056Msg 0x5058, eXfr_API5058Msg 0x5060, eXfr_API5060Msg 0x5062, eXfr_API5062Msg 0x5066, eXfr_API5066Msg 0x5067, eXfr_API5067Msg 0x5071, eXfr_API5071Msg 0x5310, eXfr_API5310Msg 0x5311, eXfr_API5311Msg 0x5400, eXfr_API5400Msg 0x9999, eXfr_API9999Msg END /****** End of sample code for WTXSAMP2.RC **********************************************/ Below are sample A2P and P2A files and a copy of the data that is generated in WTXFRPGM.LOG The first request XFERREQ0.A2P has and error the other three will work. Request XFERREQ2.P2A will work the first time but would need to be changed to update member to work on additional executions. These files would be placed in your transfer directory!! /******************** XFERREQ0.A2P FILE Begin ************************************/ [General] Type=A2P Description=WTSample Transfer Request for Test *PGM SystemName=*Default PCFileType=Text FieldDesFile= RetBlkRecs=yes AllRecords=yes FromRecord=1 ToRecord=1 [SavePCFileTo] Type=*None Name=C:\qapzcover.txt [OutputFormatTo] Type=*None Name=*None [Date] Format=MDY Separator=/ [Decimal] IgnoreErrors=yes Separator=. [Time] Format=USA Separator=: [Options] RunIconized=no ShowPercent=no Notify=no Exit=no Warn=no ToolBox=Tall CharSet=ANSI [HostFile] Member01=qgpl/qapzcoverx /******************** XFERREQ0.A2P FILE End ************************************/ /******************** XFERREQ1.A2P FILE Begin ************************************/ [General] Type=A2P Description=WTSample Transfer Request for Test *PGM SystemName=*Default PCFileType=Text FieldDesFile= RetBlkRecs=yes AllRecords=yes FromRecord=1 ToRecord=1 [SavePCFileTo] Type=*None Name=c:\qapzcover.txt [OutputFormatTo] Type=*None Name=*None [Date] Format=MDY Separator=/ [Decimal] IgnoreErrors=yes Separator=. [Time] Format=USA Separator=: [Options] RunIconized=no ShowPercent=no Notify=no Exit=no Warn=no ToolBox=Tall CharSet=ANSI [HostFile] Member01=qgpl/qapzcover /******************** XFERREQ1.A2P FILE End ************************************/ /******************** XFERREQ2.P2A FILE Begin ************************************/ [General] Type=P2A Description=Upload to AS/400 New file SystemName=*Default PCFileType=Text FieldDesFile= RetBlkRecs=yes AllRecords=yes FromRecord=1 ToRecord=1 ToHostMember=qgpl/qapzcoverz FromPCFile=c:\qapzcover.txt [SavePCFileTo] Type=*None Name=c:\qapzcover.txt [OutputFormatTo] Type=*None Name=*None [Date] Format=MDY Separator=/ [Decimal] IgnoreErrors=yes Separator=. [Time] Format=USA Separator=: [Options] RunIconized=no ShowPercent=yes Notify=yes Exit=no Warn=yes ToolBox=Tall CharSet=ANSI [HostFile] Member01=qgpl/qapzcover [Advanced] HostCreation=New file and member HostFileDes= HostMemberDes= HostFileType=Data PCFileType=Text PCRecordLen=92 HostFieldDefFile=qgpl/qapzcover HostObjAuthority=Read/Write/Delete /******************** XFERREQ2.P2A FILE End ************************************/ /******************** XFERREQ3.A2P FILE Begin ************************************/ [General] Type=A2P Description=WTSample Transfer Request for Test *PGM SystemName=*Default PCFileType=Text FieldDesFile= RetBlkRecs=yes AllRecords=yes FromRecord=1 ToRecord=1 [SavePCFileTo] Type=*None Name=c:\qapzcover.txt [OutputFormatTo] Type=*None Name=*None [Date] Format=MDY Separator=/ [Decimal] IgnoreErrors=yes Separator=. [Time] Format=USA Separator=: [Options] RunIconized=no ShowPercent=no Notify=no Exit=no Warn=no ToolBox=Tall CharSet=ANSI [HostFile] Member01=qgpl/qapzcover /******************** XFERREQ3.A2P FILE End ************************************/ /******************** Begining of Sample file WTXFRPGM.LOG **********************/ 1001 *Beg ---- 97.02.14/12:23:17 D:\DEV\WT32\XFERREQ0.A2P 1001 *Err 3000 97.02.14/12:23:30 D:\DEV\WT32\XFERREQ0.A2P Error detected by the host system.. 1001 *End ---- 97.02.14/12:23:30 D:\DEV\WT32\XFERREQ0.A2P 1002 *Beg ---- 97.02.14/12:23:43 D:\DEV\WT32\XFERREQ1.A2P 1002 *End ---- 97.02.14/12:24:01 D:\DEV\WT32\XFERREQ1.A2P 1003 *Beg ---- 97.02.14/12:24:02 D:\DEV\WT32\XFERREQ2.P2A 1003 *End ---- 97.02.14/12:24:18 D:\DEV\WT32\XFERREQ2.P2A 1004 *Beg ---- 97.02.14/12:24:19 D:\DEV\WT32\XFERREQ3.A2P 1004 *End ---- 97.02.14/12:24:30 D:\DEV\WT32\XFERREQ3.A2P /******************** End of Sample file WTXFRPGM.LOG ***************************/ Fraser's Hill and FHL are registered trademarks of Fraser's Hill Ltd. Other product and company names may be registered trademarks, trademarks, or service marks of their respective owners. FHL 14-Apr-2002 |