C# Object parameters in Outlook and Office methods

M

Michael

I am writing an Outlook COM Add-in in C# (Visual Studio .NET 2003). I am
having trouble with methods in the Outlook Object Model that have Object
parameters. These seem to be Variant parameters (whatever they are) in
Visual Basic, and I do not have VB experience. I can't seem to use any of
the methods with Object parameters successfully, since I am apparently not
passing in the proper data.

The latest one is GetItemFromID, which has the following signature (from the
Object Browser in Visual Studio):

public abstract new System.Object GetItemFromID ( System.String EntryIDItem
, System.Object EntryIDStore )

I try to pass in two strings containing the EntryID of the item and store
(the folder's StoreID), and I get the following error:

System.Runtime.InteropServices.COMException (0x92840107): Could not open the
item. Try again.

Passing in System.Reflection.Missing.Value for the StoreID (since it is
listed as an Optional parameter in VBAOL11.CHM) made no difference. The two
strings looked correct in the debugger... the ItemID is a long hex-looking
string, and the StoreID is a much longer one.

I've had similar trouble with the Temporary parameter in the Add method of
the CommandBars object (in Microsoft.Office.Core). I've passed in the C#
keyword "true" as a parameter which seems to work on my system, but not on
other systems where I installed my program:

public abstract new Microsoft.Office.Core.CommandBar Add ( System.Object
Name , System.Object Position , System.Object MenuBar , System.Object
Temporary )

I am referencing the Outlook XP PIAs directly (by browsing to the DLLs), if
that makes a difference. Am I supposed to be doing something different with
these Variant parameters from C#?

Michael
 
S

Sunny

Hi,
passing a strings to GetItemFromID works for me. But there were some
other methods where it didn't work. SO I have done:

string mystring = "blabla";
object par = mystring;

and pass par to the function.

Hope that helps
Sunny
 
M

Michael

Thanks for the suggestion. I tried it with no luck. Since a string is an
object, I suspected that it would make no difference.

Michael

Hi,
passing a strings to GetItemFromID works for me. But there were some
other methods where it didn't work. SO I have done:

string mystring = "blabla";
object par = mystring;

and pass par to the function.

Hope that helps
Sunny
 
S

Sunny

Thanks for the suggestion. I tried it with no luck. Since a string is an
object, I suspected that it would make no difference.

Michael


Sorry to hear this. Actually this worked for me for a method with a
signature (ref object). Then I needed to use the above, and it worked
here.

Btw, I think I have read somewhere, that the equivalent of variant
string for interop-ing should be StringBuilder, not string. So you may
try to use StringBuilder instead.

But, as I already said, I had no problems passing strings all the time.

Sunny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top