在非托管C使用C#COM ++项目 - >第一次机会异常在0x7697C41F(KernelBase.dll) [英] Using C# COM in unmanaged C++ project -> First-chance exception at 0x7697C41F (KernelBase.dll)

查看:1611
本文介绍了在非托管C使用C#COM ++项目 - >第一次机会异常在0x7697C41F(KernelBase.dll)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调用从C#COM项目的方法在非托管的Visual C ++的解决方案,但我不断收到一个错误

I'm trying to call methods from a C# COM project in an unmanaged Visual C++ solution, but I keep getting the next error

First-chance exception at 0x7697C41F (KernelBase.dll) in Program.exe: 0x04242420 (parameters: 0x31415927, 0x6F310000, 0x00BBDAE8).

在接下来的一段code

at the next piece of code

SalesForceNew::IMyObjectClassPtr p;
p.CreateInstance(__uuidof(SalesForceNew::TestObject)); // error
SalesForceNew::MyObject mo = p->getObject(1, "a");

不过值不出所料(5,AA)。

However the value of mo is as expected (5, "aa").

我导入TLB文件与该行的code:

I import the tlb-file with this line of code:

#import "C:\Users\Bob\Desktop\ComTest\SalesForceNew\bin\x86\Debug\SalesForceNew.tlb" named_guids

C#的项目如下:

The C# project is as follows:

接口:

using System.Runtime.InteropServices;

namespace SalesForceNew
{
    [ComVisible(true)]
    [Guid("22901ACD-CA30-4D3E-B84B-73B707026AE5")]
    public interface IMyObjectClass
    {
        MyObject getObject(int i, string s);
    }

    [ComVisible(true)]
    [StructLayout(LayoutKind.Sequential)]
    public struct MyObject
    {
        public int Getal;
        public string Text;
    }
}

类实现该接口:

the class implementing the interface:

using System.Runtime.InteropServices;

namespace SalesForceNew
{
    [ClassInterface(ClassInterfaceType.None)]
    [Guid("234A2A35-F270-458D-A67B-C834EB794B27")]
    [ComVisible(true)]
    public class TestObject : IMyObjectClass
    {
        public MyObject getObject(int i, string s)
        {
            return new MyObject() { Getal = i * 5, Text = s + s };
        }
    }


}

我查了一下选项注册COM互操作进行组装COM可见在C#中的属性COM项目。

I checked the options Register for COM interop and Make assembly COM-Visible in the properties of the C# COM project.

更新:该错误不上去,如果我们的C#COM项目的frameworkversion更改为2.0,3.0或3.5。这只能说明了当frameworkversion为4.0或4.5。

UPDATE: the error won't come up if we change the frameworkversion of the C# COM project to 2.0, 3.0 or 3.5. It only shows up when the frameworkversion is 4.0 or 4.5.

推荐答案

例外的例外,code小于0x80000000的都是非致命异常。他们往往被用来传递信息。鞋合脚在这里,除了code 0x04242420已被逆向工程来CLRDBG_NOTIFICATION_EXCEPTION_ code型,在谷歌查询编号,以查看点击率。 <一href="http://social.msdn.microsoft.com/Forums/eu/clr/thread/bca092d4-d2b5-49ef-8bbc-cbce2c67aa89">This从微软的一名员工回答可能是最可靠的:

Exceptions whose exception code is less than 0x80000000 are non-fatal exceptions. They tend to be used to pass information. The shoe fits here, exception code 0x04242420 has been reverse-engineered to CLRDBG_NOTIFICATION_EXCEPTION_CODE, type the number in a google query to see the hits. This answer from a Microsoft employee is probably the most reliable one:

出于好奇,我做了一个小挖,发现这其实是一个未公开的例外(CLRDBG_NOTIFICATION_EXCEPTION_ code)该显然是一个除了在4.0 CLR使用的托管调试的IPC协议。它应该是完全安全的,不容忽视。

Out of curiosity I did a little digging and found that this is actually an undocumented exception (CLRDBG_NOTIFICATION_EXCEPTION_CODE) that is apparently an addition to the IPC protocol used by the managed debugger in the 4.0 CLR. It should be entirely safe to ignore.

这篇关于在非托管C使用C#COM ++项目 - &GT;第一次机会异常在0x7697C41F(KernelBase.dll)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆