By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,144 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,144 IT Pros & Developers. It's quick & easy.

IDispatch GetIDsFromNames

P: n/a
Hi,

I have decleared the IDispatch interface but I'm having trouble using it.
Word.Application MSWord = new Word.ApplicationClass();
IDispatch wb = (IDispatch)MSWord.WordBasic;
int lcid = System.Globalization.CultureInfo.CurrentCulture.LC ID;

string[] rgsNames = {"DisableAutoMacros"};
int[] rgDispId;
Guid nullGUID = Guid.Empty;

int result = wb.GetIDsOfNames(ref nullGUID, rgsNames, 2,
lcid, out rgDispId);

This code sets the result to -1073741819. I can find next to no info on
this error code. Also the rgDispId stays null. What I'm I doing wrong?
Any Ideas?

Dominic Godin
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Dominic,
This code sets the result to -1073741819. I can find next to no info on
this error code. Also the rgDispId stays null. What I'm I doing wrong?
Any Ideas?


Can you post your IDispatch declaration?

You seem to have one level of indirection too much on the last
parameter, it shouldn't be ref/out since arrays are reference types.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2

P: n/a
Thanks

public interface IDispatch
{
[PreserveSig] int GetTypeInfoCount();
UCOMITypeInfo GetTypeInfo(
[MarshalAs(UnmanagedType.U4)] int iTInfo,
[MarshalAs(UnmanagedType.U4)] int lcid);
[PreserveSig] int GetIDsOfNames(
ref Guid riid,
string[] rgsNames,
[MarshalAs(UnmanagedType.U4)] int cNames,
[MarshalAs(UnmanagedType.U4)] int lcid,
int[] rgDispId); // this was out, tried ref. Both set
// the array to null
[PreserveSig] int Invoke(
int dispIdMember,
ref Guid riid,
[MarshalAs(UnmanagedType.U4)] int lcid,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
ref DISPPARAMS pDispParams,
[Out] object[] pVarResult,
ref EXCEPINFO pExcepInfo,
[Out] IntPtr[] pArgErr);
}

With the out removed this still returns an error of -1073741819 and
leaves the rgDispId array untouched.
Mattias Sjögren <ma********************@mvps.org> wrote in
news:Oa**************@TK2MSFTNGP09.phx.gbl:
Dominic,
This code sets the result to -1073741819. I can find next to no info
on this error code. Also the rgDispId stays null. What I'm I doing
wrong? Any Ideas?


Can you post your IDispatch declaration?

You seem to have one level of indirection too much on the last
parameter, it shouldn't be ref/out since arrays are reference types.

Mattias


Nov 16 '05 #3

P: n/a
Thanks

[Guid("00020400-0000-0000-c000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IDispatch
{
[PreserveSig] int GetTypeInfoCount();
UCOMITypeInfo GetTypeInfo(
[MarshalAs(UnmanagedType.U4)] int iTInfo,
[MarshalAs(UnmanagedType.U4)] int lcid);
[PreserveSig] int GetIDsOfNames(
ref Guid riid,
string[] rgsNames,
[MarshalAs(UnmanagedType.U4)] int cNames,
[MarshalAs(UnmanagedType.U4)] int lcid,
ref int[] rgDispId); // I was using out
[PreserveSig] int Invoke(
int dispIdMember,
ref Guid riid,
[MarshalAs(UnmanagedType.U4)] int lcid,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
ref DISPPARAMS pDispParams,
[Out] object[] pVarResult,
ref EXCEPINFO pExcepInfo,
[Out] IntPtr[] pArgErr);
}

Still doesn't work mind. Still get the -1073741819 error and the
rgDispId array is left untouched. Any ideas?

PS. Using a crappy newserver so sorry if this is a double post.

Mattias Sjögren <ma********************@mvps.org> wrote in
news:Oa**************@TK2MSFTNGP09.phx.gbl:
Dominic,
This code sets the result to -1073741819. I can find next to no info
on this error code. Also the rgDispId stays null. What I'm I doing
wrong? Any Ideas?


Can you post your IDispatch declaration?

You seem to have one level of indirection too much on the last
parameter, it shouldn't be ref/out since arrays are reference types.

Mattias


Nov 16 '05 #4

P: n/a
[PreserveSig] int GetIDsOfNames(
ref Guid riid,
string[] rgsNames,
[MarshalAs(UnmanagedType.U4)] int cNames,
[MarshalAs(UnmanagedType.U4)] int lcid,
ref int[] rgDispId); // I was using out


It shouldn't be ref either, try it like this

[PreserveSig] int GetIDsOfNames(
ref Guid riid,
[MarshalAs(UnmanagedType.LPArray,
ArraySubType=UnmanagedType.LPWStr)]
string[] rgsNames,
int cNames,
int lcid,
[MarshalAs(UnmanagedType.LPArray)] int[] rgDispId);

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #5

P: n/a
That did the trick, thank you ever so much.

Final interface was:

[Guid("00020400-0000-0000-c000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IDispatch
{
[PreserveSig] int GetTypeInfoCount();
UCOMITypeInfo GetTypeInfo(
[MarshalAs(UnmanagedType.U4)] int iTInfo,
[MarshalAs(UnmanagedType.U4)] int lcid);
[PreserveSig] int GetIDsOfNames(
ref Guid riid,
[MarshalAs(UnmanagedType.LPArray,
ArraySubType=UnmanagedType.LPWStr)]
string[] rgsNames,
int cNames,
int lcid,
[MarshalAs(UnmanagedType.LPArray)] int[] rgDispId);
[PreserveSig] int Invoke(
int dispIdMember,
ref Guid riid,
[MarshalAs(UnmanagedType.U4)] int lcid,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
ref DISPPARAMS pDispParams,
[MarshalAs(UnmanagedType.LPArray)][Out] object[]
pVarResult,
ref EXCEPINFO pExcepInfo,
[MarshalAs(UnmanagedType.LPArray)][Out] IntPtr[]
pArgErr);
}

Thanks again.

Dominic Godin

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.