Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C+中的C#COM字符串已损坏+;BSTR 我写了一个C++的对象,我用我的C++代码调用它。 C#COM有一些函数和事件 我在C++中注册到事件,我称之为C对象。 在某个时候,这个事件被调用,将C字符串作为参数发送到C++ BSTR中,它被破坏了。_C#_C++_Com - Fatal编程技术网

C+中的C#COM字符串已损坏+;BSTR 我写了一个C++的对象,我用我的C++代码调用它。 C#COM有一些函数和事件 我在C++中注册到事件,我称之为C对象。 在某个时候,这个事件被调用,将C字符串作为参数发送到C++ BSTR中,它被破坏了。

C+中的C#COM字符串已损坏+;BSTR 我写了一个C++的对象,我用我的C++代码调用它。 C#COM有一些函数和事件 我在C++中注册到事件,我称之为C对象。 在某个时候,这个事件被调用,将C字符串作为参数发送到C++ BSTR中,它被破坏了。,c#,c++,com,C#,C++,Com,我想尽了一切办法,到处看看:-( 有人知道为什么BSTR被破坏了吗 编辑: 重要信息: 它在x64位上工作,错误只发生在x86版本上 C#COM被编译为任何CPU。我试图将其编译为x86,但没有任何区别 CS代码,调用事件: // declaring the event and delegate public delegate void on_start_delegate(string dict_param); public event on_start_delegate on_start_cl

我想尽了一切办法,到处看看:-(

有人知道为什么BSTR被破坏了吗

编辑: 重要信息:

  • 它在x64位上工作,错误只发生在x86版本上
  • C#COM被编译为任何CPU。我试图将其编译为x86,但没有任何区别
  • CS代码,调用事件:

    // declaring the event and delegate
    public delegate void on_start_delegate(string dict_param);
    public event on_start_delegate on_start_click;
    
    void on_start(mydictionary dictparams)
    {
         string strparams = dictparams.ToString();
    
         Trace.WriteLine(strparams); // the string is fine
    
         if (on_start_click != null)
            on_start_click(strparams); // <--- Calling C++
    }
    
    BEGIN_SINK_MAP(registraion_form)
            SINK_ENTRY_INFO(SENSOR_REG_SINK_ID, __uuidof(namespace::Iregistration_form_events), 1, on_start_click, &on_start_click_info)
    END_SINK_MAP()
    
    _ATL_FUNC_INFO registraion_form::on_start_click_info = {CC_STDCALL, VT_EMPTY, 1, {VT_BSTR}};
    
    在C++中,注册到事件:

    // declaring the event and delegate
    public delegate void on_start_delegate(string dict_param);
    public event on_start_delegate on_start_click;
    
    void on_start(mydictionary dictparams)
    {
         string strparams = dictparams.ToString();
    
         Trace.WriteLine(strparams); // the string is fine
    
         if (on_start_click != null)
            on_start_click(strparams); // <--- Calling C++
    }
    
    BEGIN_SINK_MAP(registraion_form)
            SINK_ENTRY_INFO(SENSOR_REG_SINK_ID, __uuidof(namespace::Iregistration_form_events), 1, on_start_click, &on_start_click_info)
    END_SINK_MAP()
    
    _ATL_FUNC_INFO registraion_form::on_start_click_info = {CC_STDCALL, VT_EMPTY, 1, {VT_BSTR}};
    
    导致BSTR损坏的函数:

    void registration_form::on_start_click( BSTR params ) // <-- params get corrupted!
    {
    
    dictionary dictparams;
    
    std::wstringstream ss;
    ss << params;
    ss >> dictparams;
    
    // do more stuff...
    }
    
    void registration\u form::在开始时单击(BSTR参数)//dictparams;
    //做更多的事情。。。
    }
    
    再次感谢您的帮助!!!!

    “它在x64上工作”强烈暗示您存在调用约定不匹配。x64只有一个调用约定,而x86有几个


    请确保您的事件处理程序声明为stdcall。

    如果没有实际的代码片段,想法是不可能的。
    BSTR
    s不会无缘无故被损坏。请向我们展示如何调用C#COM对象。还有,是什么让您说字符串已损坏?内存中字符串的表示形式是什么?@romar.,我添加了代码。谢谢ot!它必须是STDCALL。这里没有检查,编译器会传递错误的函数引用。你是对的!!!!:-)我错过了它。。。我不知道x64有一个呼叫约定…!:-)