IDispatch GetIDsFromNames

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dominic Godin

    IDispatch GetIDsFromNames

    Hi,

    I have decleared the IDispatch interface but I'm having trouble using it.


    Word.Applicatio n MSWord = new Word.Applicatio nClass();
    IDispatch wb = (IDispatch)MSWo rd.WordBasic;
    int lcid = System.Globaliz ation.CultureIn fo.CurrentCultu re.LCID;

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

    int result = wb.GetIDsOfName s(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
  • Mattias Sjögren

    #2
    Re: IDispatch GetIDsFromNames

    Dominic,
    [color=blue]
    >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?[/color]

    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.

    Comment

    • Dominic

      #3
      Re: IDispatch GetIDsFromNames

      Thanks

      public interface IDispatch
      {
      [PreserveSig] int GetTypeInfoCoun t();
      UCOMITypeInfo GetTypeInfo(
      [MarshalAs(Unman agedType.U4)] int iTInfo,
      [MarshalAs(Unman agedType.U4)] int lcid);
      [PreserveSig] int GetIDsOfNames(
      ref Guid riid,
      string[] rgsNames,
      [MarshalAs(Unman agedType.U4)] int cNames,
      [MarshalAs(Unman agedType.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(Unman agedType.U4)] int lcid,
      [MarshalAs(Unman agedType.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 <mattias.dont.w ant.spam@mvps.o rg> wrote in
      news:Oa5C8G7JEH A.3592@TK2MSFTN GP09.phx.gbl:
      [color=blue]
      > Dominic,
      >[color=green]
      >>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?[/color]
      >
      > 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
      >[/color]

      Comment

      • Dominic

        #4
        Re: IDispatch GetIDsFromNames

        Thanks

        [Guid("00020400-0000-0000-c000-000000000046")]
        [InterfaceType(C omInterfaceType .InterfaceIsIUn known)]
        public interface IDispatch
        {
        [PreserveSig] int GetTypeInfoCoun t();
        UCOMITypeInfo GetTypeInfo(
        [MarshalAs(Unman agedType.U4)] int iTInfo,
        [MarshalAs(Unman agedType.U4)] int lcid);
        [PreserveSig] int GetIDsOfNames(
        ref Guid riid,
        string[] rgsNames,
        [MarshalAs(Unman agedType.U4)] int cNames,
        [MarshalAs(Unman agedType.U4)] int lcid,
        ref int[] rgDispId); // I was using out
        [PreserveSig] int Invoke(
        int dispIdMember,
        ref Guid riid,
        [MarshalAs(Unman agedType.U4)] int lcid,
        [MarshalAs(Unman agedType.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 <mattias.dont.w ant.spam@mvps.o rg> wrote in
        news:Oa5C8G7JEH A.3592@TK2MSFTN GP09.phx.gbl:
        [color=blue]
        > Dominic,
        >[color=green]
        >>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?[/color]
        >
        > 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
        >[/color]

        Comment

        • Mattias Sjögren

          #5
          Re: IDispatch GetIDsFromNames

          [color=blue]
          > [PreserveSig] int GetIDsOfNames(
          > ref Guid riid,
          > string[] rgsNames,
          > [MarshalAs(Unman agedType.U4)] int cNames,
          > [MarshalAs(Unman agedType.U4)] int lcid,
          > ref int[] rgDispId); // I was using out[/color]

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

          [PreserveSig] int GetIDsOfNames(
          ref Guid riid,
          [MarshalAs(Unman agedType.LPArra y,
          ArraySubType=Un managedType.LPW Str)]
          string[] rgsNames,
          int cNames,
          int lcid,
          [MarshalAs(Unman agedType.LPArra y)] 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.

          Comment

          • Dominic

            #6
            Re: IDispatch GetIDsFromNames

            That did the trick, thank you ever so much.

            Final interface was:

            [Guid("00020400-0000-0000-c000-000000000046")]
            [InterfaceType(C omInterfaceType .InterfaceIsIUn known)]
            public interface IDispatch
            {
            [PreserveSig] int GetTypeInfoCoun t();
            UCOMITypeInfo GetTypeInfo(
            [MarshalAs(Unman agedType.U4)] int iTInfo,
            [MarshalAs(Unman agedType.U4)] int lcid);
            [PreserveSig] int GetIDsOfNames(
            ref Guid riid,
            [MarshalAs(Unman agedType.LPArra y,
            ArraySubType=Un managedType.LPW Str)]
            string[] rgsNames,
            int cNames,
            int lcid,
            [MarshalAs(Unman agedType.LPArra y)] int[] rgDispId);
            [PreserveSig] int Invoke(
            int dispIdMember,
            ref Guid riid,
            [MarshalAs(Unman agedType.U4)] int lcid,
            [MarshalAs(Unman agedType.U4)] int dwFlags,
            ref DISPPARAMS pDispParams,
            [MarshalAs(Unman agedType.LPArra y)][Out] object[]
            pVarResult,
            ref EXCEPINFO pExcepInfo,
            [MarshalAs(Unman agedType.LPArra y)][Out] IntPtr[]
            pArgErr);
            }

            Thanks again.

            Dominic Godin

            Comment

            Working...