gpt4 book ai didi

c# - 向 C# COM 服务器添加一些内容并从 C++ 使用它而无需重新编译

转载 作者:行者123 更新时间:2023-11-30 03:31:44 25 4
gpt4 key购买 nike

假设

  • 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.

现在假设我向我的 managed.dll 中的一个类添加了一个方法或属性。然后B公司的unmanaged.exe就坏了。公司 B 必须使用较新的 tlb 文件重新编译它。

当我向我的 managed.dll 添加内容时,如何避免公司 B 必须重新编译他们的 unmanaged.exe

我问的原因是

  • 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.

我们怎样才能做到这一点?

我的 managed.dll 的源代码如下所示:

[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; }
}

tlb 文件由 RegAsm.exe managed.dll/tlb/codebase 生成。

unmanaged.exe 的源代码如下所示:

#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 ...
}

问候沃尔米奇

最佳答案

Microsoft 定义 IHTMLEventObj6 是有原因的。这是 IHTMLEventObj 的第 5 次增量更新。您需要做同样的事情:ITestA2 需要继承 ITestA 并添加额外的方法。

关于c# - 向 C# COM 服务器添加一些内容并从 C++ 使用它而无需重新编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43975117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com