none
Qustion in the IL about Marshal RRS feed

  • Question

  • 今天看一篇文章讲述怎么在net环境下使用com组件中的IL修改的代码中看到了
    I see this code
    .method public hidebysig newslot virtual abstract 
              instance void  MyNextLongs([in] int32 nReq, 
                                    // Replace this: [out] int32& rgelt, 
                                    // With this: 
                                    [out] int32[] marshal([ + 1]) rgelt, 
                                    [out] int32& pnFetched) runtime managed internalcall

    in a article from MSDN about interoperating with a COM server that returns conformant arrays, and find that  'Marshal([+1])' which makes me confuesd even if i had search in the internet, what's mean and how to use the number in the '[+????]'?
    Saturday, December 19, 2009 11:04 AM

Answers

  • Hi oceanchow,

    The +1 means that the number of elements in the int32[] array is given at runtime by the first parameter passed to the method ((i.e. parameter number 1: int32 nReq).

    Please refer to Ecma-335 (Partition II, p. 22) for further details.

    Marcel
    Saturday, December 19, 2009 9:36 PM

All replies

  • Hi oceanchow,

    The +1 means that the number of elements in the int32[] array is given at runtime by the first parameter passed to the method ((i.e. parameter number 1: int32 nReq).

    Please refer to Ecma-335 (Partition II, p. 22) for further details.

    Marcel
    Saturday, December 19, 2009 9:36 PM
  • Hi Roma,
    Thanks for your help and the pdf doc, but in the pdf, i saw these words:  

    Array of NativeType with runtime supplied
    element size. The Int32 specifies a parameter to
    the current method (counting from parameter
    number 0) that, at runtime, will contain the size
    of an element of the array in bytes.  Can only be
    applied to methods, not fields.

    what's the parameter number 0 in that example? According to the description, there are two parameter in the method named MyNextLongs, I think:

    the parameter number 0 is the first paramter(int32 nReq), the parameter 1 must be the second paramter(the array), not the first paramter.Am i right? But this conclusion can't make sense.

    would you expain it a bit more?

    At the end of the description, it said 'can only be applied to methods,not fields', but if in the fields, how to solve?
    i.e
    .class public sequential ansi sealed beforefieldinit AA
           extends [mscorlib]System.ValueType
    {
      .pack 4
      .size 0
      .field public uint16 length
      .field public native int m_BBList //m_BBList is an array which    element is the struct named m_BB defined by user,the length of the array is defined by the first paramenter 'length'
    
      // .field public  marshal( ?????insert what???) valuetype m_BB m_BBList
    }

    if i want to modify the declaration of the last field for using in net, how?


    tks again.
    • Edited by oceanchow Sunday, December 20, 2009 4:07 PM add some import words
    Sunday, December 20, 2009 10:07 AM
  • Hi oceanchow,

    Well, I agree, it's not very clearly formulated. Take a look at the example down on page 22 of ECMA-335, second partition:

    .method int32 M2( int32 marshal(int32), bool[] marshal(bool[+1]) )

    The documentation states: "Method M2 (above) takes two arguments: an int32, and an array of bools: the number of elements in that array is given by the value of the first parameter."

    I hope this answers your *original* question.

    Thank you
    Marcel

    Monday, December 21, 2009 2:29 PM
  • Hi Roma,
    The description is not clearly, and i had seen a code listed below which makes me confuesd

    .method int32 M2(int32 marshal(int32),bool[] marshal(bool[+0]),int32 marshal(int32))

    Tuesday, December 22, 2009 12:20 AM
  • Where does this code come from? It sure looks confusing.

    In your original post you asked about the meaning of marshal([ + 1]) and how to use the Int32 metadata +1.

    The knowledge base article you were refering to (http://support.microsoft.com/kb/305990/en-us) explains that in order to interoperate with the COM server you have to modify some method signatures by disassembling the tlbimp.exe-generated .net interop assembly, changing the way data is marshalled, and reassembling it again. And if you look at the way the c# client interoperates with the COM server, you should notice that the array's length is passed as the first parameter:

    icao.MyNextLongs ( q.GetLength(0), q, out cnt );
    

    Compare this to the CIL code from your original post and to the ECMA-335 documentation I pointed to, and you have your answer.

    Thank you.
    Marcel

     

    Tuesday, December 22, 2009 10:42 AM
  • OK,I know,tks for your help.
    that IL is copied from my friends, he also copied from internet but can't remember where it come from
    Wednesday, December 23, 2009 1:54 AM