English 中文(简体)
What happens if I violate the requirements imposed on ProgIDs?
原标题:

This MSDN article states that any ProgID must meet several formal requirements, length restriction included. However nothing is said about what happens if those are violated.

I found several places in our codebase where ProgIDs are longer than 39 characters, still everything seems to work allright for them, ProgIDFromCLSID() and CLSIDFromProgID() included.

Since violating those requirements is quite easy it would be very interesting to know what are the real possible consequences of such violations?

最佳回答

I guess what you get is undefined behavior. This can range from normal functioning to crashes, kittens being eaten, firstborns sacrificed, &c.

More to the point, some requirements probably tell you a few things:

  • No more than 39 characters: Other software might use a fixed-size buffer of 40 chars to store a ProgID. They would therefore only have the first 39 and might not find your ProgID if it s longer.
  • Not start with a digit; contain no punctuation except periods: Again, this is a contract. Software may rely on this to verify ProgIDs it gets from somewhere that they are really ProgIDs and not something entirely different, for example.

Windows might not bite you immediately but other things might.

问题回答

I don t have an answer yet -- I m researching this problem, myself -- but I did come across this:

It is common practice in managed code to specify namespaces and typenames that are verbose, but this can easily exceed the maximum allowed length of a ProgId (39 characters). If you do this, there s no indication of the problem until you try to register the add-in with Excel – and even then, Excel simply tells you that the add-in is invalid, without providing any more detail. To avoid this problem, you should always specify a ProgId explicitly, using the ProgId attribute. Also remember that underscores are legal in managed code, but illegal in ProgIds.

in a blog by Andrew Whitechapel which suggests that the limit may be more than just a convention enforced by programmers using short buffers.





相关问题
How can i add a button to all windows explorer instances?

I am trying to add a button to one of the existing tool bars in any windows explorer instance. After much research i figured out that BHO (browser helper objects) are the best way to hook to ...

Hunting memory leaks

I m finding leaked heap blocks by using the following command in WinDbg !heap –l With each leaked heap block I get, I m running to following to get the stack trace. !heap -p -a leakedheapblock The ...

Why use CComBSTR instead of just passing a WCHAR*?

I m new to COM. What exactly is the advantage of replacing: L"String" with CComBSTR(L"String") I can see a changelist in the COM part of my .NET application where all strings are replaced in this ...

IThumbnailProvider and IInitializeWithItem

I am trying to develop an IThumbnailProvider for use in Windows 7. Since this particular thumbnail would also be dependant on some other files in the same directory, I need to use something other than ...

Getting a byte array from out of process C++ COM to C#

What s the best way to get a chunk of memory (i.e. void*) from a COM server to C#? We have been using an IStream (using CreateStreamOnHGlobal) and passing that back, which worked. However when we ...

COM Basic links

folks can you provide me the tutorial link or .pdf for learning basic COM?. i do google it.. still i recommend answers of stackoverflow so please pass me.. Thanks

热门标签