Windows COM Support / WinCOM examples |
This section provides a Wincom and Outlook example.
DEFINE outapp INTEGER DEFINE outit INTEGER DEFINE outcon INTEGER DEFINE outsav INTEGER MAIN DEFINE result INTEGER DEFINE str STRING --initialization of global variables LET outapp = -1 LET outit = -1 LET outcon = -1 LET outsav = -1 --first, we must create an Instance of an Outlook Application CALL ui.interface.frontcall("WinCOM", "CreateInstance", ["Outlook.Application"], [outapp]) CALL CheckError(outapp, __LINE__) --then, creating a contact object CALL ui.interface.frontcall("WinCOM", "CallMethod", [outapp, "CreateItem(olContactItem)"], [outit]) CALL CheckError(outit, __LINE__) --then, displaying the contact form CALL ui.interface.frontCall("WinCOM", "CallMethod", [outit, "Display"], [outcon]) CALL CheckError(outcon, __LINE__) --CALL SetProperty to fill the various fields with the values you expect #First Name CALL ui.interface.frontCall("WinCOM", "SetProperty", [outit, "FirstName", "Lionel"], [result]) CALL CheckError(result, __LINE__) #1st email address CALL ui.interface.frontCall("WinCOM", "SetProperty", [outit, "Email1Address", "lif@4js.com"], [result]) CALL CheckError(result, __LINE__) #Business address CALL ui.interface.frontCall("WinCOM", "SetProperty", [outit, "BusinessAddress", "1 rue de Berne"], [result]) CALL CheckError(result, __LINE__) --then, CALL GetProperty to check the values again CALL ui.Interface.frontCall("WinCOM", "GetProperty", [outit, "FirstName"], [str]) CALL CheckError(str, __LINE__) DISPLAY "First Name of the new contact is " || str CALL ui.Interface.frontCall("WinCOM", "GetProperty", [outit, "Email1Address"], [str]) CALL CheckError(str, __LINE__) DISPLAY "1st email of the new contact is " || str CALL ui.Interface.frontCall("WinCOM", "GetProperty", [outit, "BusinessAddress"], [str]) CALL CheckError(str, __LINE__) DISPLAY "Business Address of the new contact is " || str --at the end, saving the contact CALL ui.interface.frontCall("WinCOM", "CallMethod", [outit, "Save"], [outsav]) CALL CheckError(outsav, __LINE__) --then Free the memory on the client side CALL freeMemory() END MAIN FUNCTION freeMemory() DEFINE res INTEGER IF outit != -1 THEN CALL ui.Interface.frontCall("WinCOM","ReleaseInstance", [outit], [res] ) END IF IF outapp != -1 THEN CALL ui.Interface.frontCall("WinCOM","ReleaseInstance", [outapp], [res] ) END IF END FUNCTION FUNCTION checkError(res, lin) DEFINE res INTEGER DEFINE lin INTEGER DEFINE mess STRING IF res = -1 THEN DISPLAY "COM Error for call at line:", lin CALL ui.Interface.frontCall("WinCOM","GetError",[],[mess]) DISPLAY mess --let's release the memory on the GDC side CALL freeMemory() DISPLAY "Exit with COM Error." EXIT PROGRAM (-1) END IF END FUNCTION