OK, from a quick look at your source code (and a run of your program) I'm guessing you need to use ray casting but slightly different to how you are using it at the moment.
You ray cast from the camera position to the object position and if the object is not the first thing the ray hits then it is not in view.
This is only really 100% relevant for your lens flare idea, other parts of the object might still be visible to the camera. As you are trying to show the lens flare only when the sun/light source is visible this is probably good enough for what you want to achieve.
There are ray cast commands in DBP but I would suggest using Sparky's collision for Ray Casting (found here):
http://forum.thegamecreators.com/?m=forum_view&t=74762&b=5
The command is more or less:
return integer=SC_rayCast (objNum, oldx, oldy, oldz, newx, newy, newz, excludeObj)
objNum is the object you are searching for a collision with (or zero for all objects)
returned integer is either 1 for collision or 0 for no collision, if you used zero then it will provide the object number of the first object it collided with.
my suggestion is to add something like this in your code to check if the sun is in sight:
visible = SC_rayCast (SunObject, camera position x, camera position y, camera position z, object position x(SunObject), object position y(SunObject), object position z(SunObject), LensPlane)
Then if visible returns as 1 you position your lens flare object a set distance between the camera and the SunObject, point it at the camera then apply some kind of offset based on how far from the centre of the screen the SunObject is.
I hope this helps!
EDIT: Another way might be to use a sprite as the lens flare and place it based on the position of the sun object.