Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with Outlook?
Message
From
02/05/2024 01:14:28
 
 
To
01/05/2024 15:58:38
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01687959
Message ID:
01687970
Views:
36
I already answered in another forum, from now on I suggest that the discussion continues in this forum.

To repeat, I have two suggestions
1. Maybe the release process needs some time to finish, so add some kind of delay.
2. Try to use GetObject() instad of CreateObject(). You can do this in a Try-Endtry block. If GetObject() fails, then you use CreateObject().

Update, one important question:
Is Outlook already running when you run your code?

>Hello Tore,
>
>Here is the revised code.
>
>
>lContinuer = .F.
>oOutlook = CREATEOBJECT("Outlook.Application")
>IF VARTYPE( oOutlook) = "U"
>	DO FORM ts_Messagebox WITH I("Outlook must be running")
>	oOutlook = null
>	RELEASE oOutlook	
>	QUIT 
>ELSE 
>	oMapi = oOutlook.GetNamespace("MAPI")
>	outlookAccounts = oMapi.Accounts
>	FOR i = 1 TO outlookAccounts.Count
>	    IF outlookAccounts.Item(i).DisplayName = "anemail@mycompany.com" THEN
>			lContinuer = .T.
>	        EXIT
>	    ENDIF
>	ENDFOR
>	outlookAccounts = null
>	RELEASE outlookAccounts
>	oMAPI = null
>	RELEASE oMAPI
>
>	IF !lContinuer
>		DO FORM ts_Messagebox WITH I("You can't use the application.")
>		oOutlook = null
>		RELEASE oOutlook	
>		quit
>	ENDIF 
>ENDIF 
>oOutlook = null
>RELEASE oOutlook	
>
>
>Even after the adjustments I have the same problem. Couple of things to mention though. If I run my code through the debugger First execution runs ok. but after that I have to reboot my computer. If I run through compiled app the message "You can't use the application." is not even shown. and after the non-message I have to reboot my computer if I want to run that code again.
>
>
>>>>>Hello all,
>>>>>
>>>>>I execute this code. First time I execute everything's fine. Second time my application hangs and I have to reboot my computer. I guess that there could be something related to outlook still in memory. But I don't understand.
>>>>>
>>>>>
>>>>>
>>>>>lContinue = .F.
>>>>>
>>>>>oOutlook = CREATEOBJECT("Outlook.Application")
>>>>>outlookAccounts = oOutlook.GetNamespace("MAPI").Accounts
>>>>>FOR i = 1 TO outlookAccounts.Count
>>>>>    IF outlookAccounts.Item(i).DisplayName = "myemail@mycompany.com" THEN
>>>>>		lContinue = .T.
>>>>>        EXIT
>>>>>    ENDIF
>>>>>ENDFOR
>>>>>oOutlook = null 
>>>>>outlookAccounts = null
>>>>>
>>>>>IF !lContinue
>>>>>	Messagebox( "You can't use that application.")
>>>>>	QUIT
>>>>>ENDIF 
>>>>>
>>>>
>>>>You must release the variables in reverse order.
>>>>It's also recommended to use Release to absolutely make sure that the variables are released.
>>>>IOW
>>>>
>>>>
outlookAccounts = null
>>>>outlook = null
>>>>release outlookAccounts && recommended 
>>>>release outlook && recommended
>>>>
>>>
>>>This can get unwieldy if lots of pointers are added or app grows
>>>First step for automatic management is to create a class
>>>sporting an array of names / pointer descriptors (not pointers)
>>>and increment length of array with new pointer descriptor
>>>whenever a new special (COM, Base Mem, Dotnet) pointer is added
>>>and reference it there.
>>>Release just walks this array from top to bottom.
>>>Use recursively if you have "pointer groups" like in the example
>>>*and* a need to free those special groups before form or app quit.
>>>
>>>my 0.0022€
>>>thomas
>>
>>As long as you avoid adding more variables or properties, you should be safe.
Previous
Reply
Map
View

Click here to load this message in the networking platform