Announcement

Collapse
No announcement yet.

DISPID Numbering

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DISPID Numbering

    I'm trying to spend some time on using objects. Just never got around to it so now seemed like a good time.

    First random question is why DISPID numbers seem to be assigned randomly in code that I've seen.

    With control ID's I start at 500 or so and than assign the next as 501, 502, ... etc.

    But object code I've seen doesn't seem to do that. For example, in Help, <76> is used in one of the METHOD code examples.


  • #2
    The number isn't important as long as your "object" returns the right DispID number when GetIDsOfNames is called internally.

    If you use early binding, the code generated by the compiler calls the Invoke method directly passing the DispID that finds in the interface declaration.

    If you use late binding, the code generated by the compiler calls GetIDsOfNames to map the method name with its DispID and then calls Invoke.
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Originally posted by Gary Beene View Post
      With control ID's I start at 500 or so and than assign the next as 501, 502, ... etc.
      Why?

      (Are you conflating Control IDs with user defined Windows message? )

      Comment


      • #4
        Originally posted by Gary Beene View Post
        But object code I've seen doesn't seem to do that. For example, in Help, <76> is used in one of the METHOD code examples.
        Take a look at Help for PowerTime, PowerThread, PowerArray, StringBuilder.. You will see that the DISPIDs generally start at 1 and are generally sequential. (With the odd gap, probably as a result of programming changes.)

        Comment


        • #5
          Howdy, Jose!
          I take your response to mean that there's no particular reason to order the DISPID. It's just that except for what Stuart just mentioned, I'd not seen any example of ordered DISPIDs (hardly did a detailed search).

          Howdy, Stuart!
          Yep, so they are.

          As for why the id starting point ... from Help "... best practice suggests identifiers should start at 100 ...". So I could use 100, but somewhere along the way I forgot the starting point and started using 500 because I was certain the starting point was a smaller number. Now, it's just become an unjustified habit.

          Comment


          • #6
            Originally posted by Gary Beene View Post
            As for why the id starting point ... from Help "... best practice suggests identifiers should start at 100 ...". So I could use 100, but somewhere along the way I forgot the starting point and started using 500 because I was certain the starting point was a smaller number. Now, it's just become an unjustified habit.
            I've got into the habit of using the PBForms default of 1001 and above for control IDs

            Incidentally PBForms uses 101... for dialog IDs. I've never seen anywhere that you can actually use a Dialog ID, do you know of any?


            Comment


            • #7
              > I take your response to mean that there's no particular reason to order the DISPID. It's just that except for what Stuart just mentioned, I'd not seen any example of ordered DISPIDs (hardly did a detailed search).

              Like with the control identifiers, it doesn't matter as long as they don't conflict with reserved numbers.

              Regarding DispIDs, the reserved numbers are:
              See: https://docs.microsoft.com/en-us/ope...0-7264856a10c5

              DISPID_VALUE

              0

              This MUST designate the default member for the object. The default member is the member that best represents the automation server.

              DISPID_UNKNOWN

              -1

              The value MUST be returned by GetIDsOfNames (see section 3.1.4.3) to indicate that a member or parameter name was not found.

              DISPID_PROPERTYPUT

              -3

              This MUST designate the parameter that receives the value of an assignment in a DISPATCH PROPERTYPUT or DISPATCH PROPERTYPUTREF invocation (see section 3.1.4.4).

              DISPID_NEWENUM

              -4

              -----------------------------------------------------------------------------------------

              Besides, some servers such Excel also use DispIDs for named parameters.

              Automation is a flexible, but inneficient way of working with COM. It was designed mainly for scripting languages that can't use direct interface calls.
              Forum: http://www.jose.it-berater.org/smfforum/index.php

              Comment

              Working...
              X