Thanks, I'll give it a go. Faint of heart I'm not, but neither am I a C++ programmer! Variants are the only option for the COM add-in due to interfacing with VB (or more importantly, due to the object types).
Main Topics
Browse All TopicsI have a COM written to be used in conjunction with a VB Outlook add-in. One problem I would like to resolve is to properly handle invalid parameters being passed to the add-in. For example, one function is as below. This function takes a MAPIFolder and returns an array containing information about the folder (i.e. all subfolders, recursed).
The problem occurs when an invalid object is passed as a parameter (e.g. the folder object is VB Nothing, or unset). This currently causes a GPF. While I have made all possible checks in the VB code before calling this routine, I would rather the C++ function failed gracefully.
So... How do I check for a valid object so that I can simply return immediately if not supplied?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I'm sorry but I do not understand your mail. What did you pass to this function? LPDISPATH surely is a valid IDispatch interface or not?
What should the MapiObject parameter be?
The code you show looks quite ok to me, the only code which seems not to be ok is return NULL, This does not look ok to me but I may be wrong.
I do also not understand what you mean with this from your initial question
rameter (e.g. the folder object is VB Nothing, or unset)
should that be the first,second or third parameter.
I've the impression you use some wrapper around the MAPI stuff.
Common tasks are show here:
http://msdn.microsoft.com/
if you however do IDispatch programming with C/C++ you probably want to use the disphelper.c file also
http://disphelper.sourcefo
In your case you just have on parameter while accessing the getter but if you do have more parameter you also have to be sure that you pass in the the parmater in reverse order.
But that's another story. Without understanding where the problem is I can not do more than trying to give you hints. I'm still absolutly unsure what you like to achieve.
Regards
Friedrich
The null return is fine - if null is returned from the above function then the calling code returns an E_NOINTERFACE code. I don't mind null returns, I can check for them - but what is happening is if I pass the VB value Nothing in as a parameter instead of the expected MAPIObject, then I get a GPF rather than an error (which is what I want).
There is no wrapper beyond the above code. From VB, I would call EnumerateFolders passing a folder object as pFolderItem. However, if I pass Nothing, I don't get an error, I get a crash, which is not what I want (obviously!). The problem being that sometimes if there is an error elsewhere in the VB code, a parameter may end up being Nothing, so I just need an error returned.
I don't know how to explain it any further... EnumerateFolders is the function presented via COM to VB.
I presume the:
if (!unk) return E_NOINTERFACE;
Is in fact checking whether unk is null, and if so returning E_NOINTERFACE?!
Nothing in VB is a value, or in the case of an object (which this is) it means that it doesn't in fact refer to ANY object.
http://msdn.microso
I test for VT_EMPTY (but this test doesn't catch it). When I try testing for NULL (with either pFolderItem==NULL, or !pFolderItem syntax) I receive a compile error:
error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'struct tagVARIANT' (or there is no a
cceptable conversion)
Thing is, as I only catch VARIANTS that are either VT_DISPATCH or VT_DISPATCH | VT_BYREF, anything that isn't that type will result in an error. Which means that NOTHING is still being passed as VT_DISPATCH.
Based on writing the above, I suddenly realised that I should be testing the I_DISPATCH interface. The VARIANT is passed (as VT_dispatch), but the pointer to the I_DISPATCH is NULL when VB passes Nothing.
So, I modified the function below, and it now returns an error instead of crashing - which was the required result. :-)
Business Accounts
Answer for Membership
by: fridomPosted on 2009-10-06 at 03:15:02ID: 25503380
probably something along
en-us/libr ary/ms2216 27.aspx
if (pFolderItem.vt == (VT_EMPTY) or ....
// fail with INVALID_ARG
the Variant type really is not for the faint of heart ;-)
see e.g
http://msdn.microsoft.com/
Regards
Friedrich