C#: Fixed Function ID in COM DLL
-
I have built a COM DLL with a number of functions in version 1: - OnlineAvailCheck_V2 --> first public function - DownloadProductInfo_V2 --> second public function - DownloadPriceInfo_V2 --> third public function The COM DLL is called from an external application; the functions appear in the same order as shown above. In version 2, the DownloadProductInfo function has become obsolete, and needs to be replaced by V31 - OnlineAvailCheck_V2 --> first public function - DownloadProductInfo_V2 --> becomes private - DownloadPriceInfo_V2 --> second public function - DownloadProductInfo_V31 --> third public function If I make the V2 function private (because it must no longer be used), the external application makes a shift in the code: all references to DownloadProductInfo_V2 are now replaced by references to the third public function, i.e. DownloadPriceInfo_V2 function. Is there any way I can give a fixed sequence number to the functions, so that I can avoid the shift? Or is there any other way to deal with this? Thank you.
Dox Girl, where are you?
-
I have built a COM DLL with a number of functions in version 1: - OnlineAvailCheck_V2 --> first public function - DownloadProductInfo_V2 --> second public function - DownloadPriceInfo_V2 --> third public function The COM DLL is called from an external application; the functions appear in the same order as shown above. In version 2, the DownloadProductInfo function has become obsolete, and needs to be replaced by V31 - OnlineAvailCheck_V2 --> first public function - DownloadProductInfo_V2 --> becomes private - DownloadPriceInfo_V2 --> second public function - DownloadProductInfo_V31 --> third public function If I make the V2 function private (because it must no longer be used), the external application makes a shift in the code: all references to DownloadProductInfo_V2 are now replaced by references to the third public function, i.e. DownloadPriceInfo_V2 function. Is there any way I can give a fixed sequence number to the functions, so that I can avoid the shift? Or is there any other way to deal with this? Thank you.
Dox Girl, where are you?
Use the
DispIdAttribute
attribute[^] to specify the COM dispatch identifier for your methods and properties. That way, the order doesn't matter.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I have built a COM DLL with a number of functions in version 1: - OnlineAvailCheck_V2 --> first public function - DownloadProductInfo_V2 --> second public function - DownloadPriceInfo_V2 --> third public function The COM DLL is called from an external application; the functions appear in the same order as shown above. In version 2, the DownloadProductInfo function has become obsolete, and needs to be replaced by V31 - OnlineAvailCheck_V2 --> first public function - DownloadProductInfo_V2 --> becomes private - DownloadPriceInfo_V2 --> second public function - DownloadProductInfo_V31 --> third public function If I make the V2 function private (because it must no longer be used), the external application makes a shift in the code: all references to DownloadProductInfo_V2 are now replaced by references to the third public function, i.e. DownloadPriceInfo_V2 function. Is there any way I can give a fixed sequence number to the functions, so that I can avoid the shift? Or is there any other way to deal with this? Thank you.
Dox Girl, where are you?
As a side note, once interfaces are defined they should be fixed unless you are willing to re-compile all clients also. So if you want to alter the interface you should re-compile your client too. If you don't want to re-compile the client, then implement a new interface and have calls to your old interface redirect or forward to the method on the new interface. The redundant methods will just remain there, you can have them return errors if you want to indicate they shouldn't be called. Any new client, or client you don't mind re-compiling, will reference your new interface. This way all old and new clients still see the interfaces they were compiled against. You might be able to configure the interface forwarding for you automatically using the registry, it's been a while and back in the day interface forwarding was handled by the compiled and COM registration tools.