c#


Add something to a C# COM server and use it from C++ without recompiling


Let's assume
I'm working for company A and I provide a C# DLL called managed.dll which is COM visible. I provide as well the TLB file called managed.tlb.
a company B is using my managed.dll in a C++ EXE called unmanaged.exe.
a customer C has to get the managed.dll from my company A and the unmanaged.exe from company B. The reason for that is that company B is not allowed to redistribute the managed.dll from company A.
Now let's assume I add a method or property to one of my classes in my managed.dll. Then the unmanaged.exe from company B is broken. Company B has to recompile it with the newer tlb-file.
How can I avoid that company B has to recompile their unmanaged.exe when I add something to my managed.dll?
The reason why I'm asking is
I've no control when company B is recompiling or releasing their unmanaged.exe. Even if I provide my managed.dll to company B every time I've added something.
I've no control which versions of the managed.dll and unmanaged.exe the customer C is using.
company B would like to claim that their unmanaged.exe V1.0 is working with my managed.dll V1.0 or newer.
How can we achieve that?
The source code of my managed.dll looks like that:
[Guid("852e5991-ddcc-56dd-8e13-90dcaf11ebe5")]
[ComVisible(true)]
public interface ITestA
{
string DummyString();
int DummyInt();
}
[Guid("41916928-6bea-43de-bedb-318df340e7b8")]
[ComVisible(true)]
[ComDefaultInterface(typeof(ITestA))]
public class TestA : ITestA
{
public string DummyString() { return "Dummy"; }
public int DummyInt() { return 123; }
}
The tlb-file is generated with RegAsm.exe managed.dll /tlb /codebase.
The source code of the unmanaged.exe looks like that:
#include "stdafx.h"
#import "managed.tlb"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = CoInitialize(NULL); // Init COM
IClassAPtr pClassA(__uuidof(ClassA));
// and so on ...
}
Regards Wollmich
There's a reason Microsoft defined IHTMLEventObj6. That's the 5th incremental update of IHTMLEventObj. You'll need to do the same: ITestA2 will need to inherit ITestA and add extra methods.
It turned out that I've to provide new interfaces (like ITestA2, ITestA3, etc.) if I want to add new methods or properties to my managed.dll.
So the source code of the managed.dll could be extended like that:
[Guid("5ff6c41a-6e4c-4d96-8e5e-72a560715b56")]
[ComVisible(true)]
public interface ITestA2
{
string DummyString();
int DummyInt();
bool DummyBool(); // new method
}
[Guid("d5b8f4b5-d33f-4e7d-866c-ef0844216a3a")]
[ComVisible(true)]
[ComDefaultInterface(typeof(ITestA2))]
public class TestA2 : TestA, ITestA2
{
public bool DummyBool() { return true; }
}
Remarks for .NET
In COM interfaces can inherit from one another. However the .NET implementation that exposes the .NET interface to COM does not support inheritance. Therefore you must replicate any interface members in a base interface to the derived interface.
see COM Interop: Base class properties not exposed to COM.

Related Links

Dynamically Generated TextBoxes
No output from my C# calculator [closed]
Add items to custom ListBox
List<> Iteration performance
Azure build fails using ReservedIP
How to improve JSON deserialization speed in .Net? (JSON.net or other?)
Navigating to a new page from the View Model in Windows Phone 8.1 universal app
saving Images in isolated storage generate 'Invalid cross-thread access.'
Need to refresh chrome browser using C#
Stream from IP cam C#
How do I replace the behaviour of Web API model binding so that instead of Null I receive a new instance when no parameters are passed in
C# displayed value is not the same as in debugger
How do I set Header or Title for CheckedListBox
convert group by query to linq
How to give user an equivalent Excel-VBA environment for my application in C#
How to return type as a result of method execution

Categories

HOME
drupal
skype-for-business
alasql
opencv4android
liquibase
esxi
mailchimp
powerquery
servicenow
sahi
google-app-maker
mongoimport
ndepend
velocity
elastalert
xmlhttprequest
mbed
element
lambda-calculus
nsoperation
powerpivot
geography
hl7-fhir
jira-zephyr
sasl
knapsack-problem
expressionengine
traveling-salesman
android-cursorloader
multiple-inheritance
restangular
sphinx4
overflow
multilanguage
qt-designer
luhn
android-scrollview
asp.net-webhooks
border-layout
client-server
pygraphviz
origami
office-interop
keychain
ape-phylo
amazon-rds-aurora
pexpect
gradlew
niagara-ax
remap
beanshell
jcifs
senti-wordnet
cc
business-catalyst
suitesparse
sqlproj
sharing
fileopendialog
copy-constructor
indoor-positioning-system
boost-bind
std
bluetooth-lowenergy-4.2
php-gd
biginsights
om
first-order-logic
dcg
playn
genome
valdr-bean-validation
optimistic-locking
static-files
lwuit
redmine-plugins
windows-search
indic
xts
mvcgrid
enquire.js
power-management
kernel-density
netbeans-plugins
grape-api
aspnet-compiler
infomaker
listpicker
nx
gpl
moonscript
volatility
quit
gssapi
states
winrt-async
flatten
pdf-reader
parsec
unordered-set
advanceddatagrid
facebook-winjs-sdk
httppostedfilebase
cryptolicensing
lgpl
iphone-maps
dojox.gfx
opengl-to-opengles
qlibrary
disk-based

Resources

Encrypt Message