c# - COM/DCOM : Server stub does not allocate memory for new methods in existing interface

标签 c# c++ com access-violation dcom

我是 COM 新手。我的任务是用新功能扩展现有的 COM 服务器。扩展或重写现有方法工作正常,但是,我添加了一个返回数字的新方法,但在向指针位置写入一个简单值时出现异常(0xC0000005:访问冲突写入位置...),即使代码很艰难与现有方法完全相同。新方法被执行,因为其中的断点正在工作。我究竟做错了什么?似乎服务器 stub 没有为新方法分配内存。测试服务器方法的客户端是用C#编写的。服务器和测试客户端在同一台机器上执行。

.idl 文件:

[id(19)] HRESULT GetLoggingLevel
(
    [out, retval] long* Level
);
[id(190)] HRESULT GetLoggingLevelNew
(
    [out, retval] long* Level
);

COM服务器的.cpp文件:

STDMETHODIMP DeviceControl::GetLoggingLevel(LONG * Level)
{
    *Level = 43; // works
    return S_OK;
}
STDMETHODIMP DeviceControl::GetLoggingLevelNew(LONG * Level)
{
    *Level = 42; // acces violation writing location [Level]
    return S_OK;
}

测试客户端Form1.cs

private void Form1_Load(object sender, EventArgs e)
{
    m_deviceControl = new MechLib.DeviceControl();
    int foo = m_deviceControl.GetLoggingLevel(); // foo = 43
    int bar = m_deviceControl.GetLoggingLevelNew(); // server crashes
    ...

最佳答案

如果您更改了 COM 接口(interface),则必须为其分配一个新的 GUID。如果不这样做,可能会导致错误的代理/ stub 被用于您的接口(interface),这可能不会影响您的新方法......

关于c# - COM/DCOM : Server stub does not allocate memory for new methods in existing interface,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19786071/

相关文章:

c# - 在 Visual C# Express 2010 和 .net 4 中使用 NUnit

c# - 每个套接字地址(协议(protocol)/网络地址/端口)通常只允许使用一次

c++ - 多播大数据包包含到多个客户端的所有信息与到目标客户端的单个数据包

c++ - 在 C++ 中查找大乘法的余数

c++ - 如何将 _bstr_t 转换为 CString

c# - 使用 Gtk 检测双击#

c# - 在dragablz :TabablzControl wpf mvvm的所有其他选项卡中显示的另一个选项卡中具有相似长度的文本框的虚线

c# - 无法从 C# 调试非托管 Dll

c# - COM:当我将 COM 变量放入方法中时,引用计数器会增加吗?

c++ - 实例化 COM 和 ATL 类型