本文介绍了从C#导出COM组件时的命名问题(小写/大写)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#COM DLL,它定义了一些我从C ++ ATL / COM服务器使用的接口/类型。
有时,无论是在我的计算机上还是在我构建相同项目的其他计算机(ATL * .exe和C#DLL)上随机出现,我都会收到与导出的C#结构成员有关的不同编译错误。 COM接口的一部分。下面是一个示例:

I have a C# COM DLL that defines some interfaces/types that I use from a C++ ATL/COM server.From time to time, be it on my machine, or randomly on other machines where I build the same projects (the ATL *.exe and the C# DLL) I get different compile errors related to exported C# struct members that are part of the COM interface. Here is an example:

public enum TemporaryPolicyType
{
    UntilTime = 0,
    ForNextMinutes
}

[Guid("6F8CD968-DA76-44CA-B4E1-C495AB5003BD")]
public struct TemporaryPolicyData
{
    public TemporaryPolicyType Type;
    public DateTime Timestamp;
    public DateTime EndTime;
    public int EchartMinutes;
}

例如,在这种情况下,C#有时会导出 ,在某些计算机上,成员 Type具有小写字母,在其他一些使用它的代码中就可以正常工作。

For example in this particular case, C# will "export" sometimes, on some machines, member "Type" with lowercase letters, and on some other machines using it like it is in code will work just fine.

I我正在使用VS 2010。

I am using VS 2010.

推荐答案

这是类型库的已知问题。实际上,它是出于非常模糊的原因而设计的,几乎可以肯定与不知道读取类型库的编译器是否对大小写有关。基本编译器不是,C ++编译器是。该修复程序是粗略的,但是它不会按用途对标识符进行分类。

This is a known problem with type libraries. It is in fact by design for very obscure reasons, almost certainly having something to do with not knowing whether the compiler that reads the type library is sensitive to casing. A Basic compiler is not, a C++ compiler is. The fix was crude however, it does not classify the identifier by usage.

如果在之前任何声明,您的结构声明也包含一个名为类型,其余的标识符将使用第一个标识符的字母大写。最意外的情况是它是方法参数的名称,通常以小写形式编写。如果类型是属性的名称,则将其重命名为类型。粗糙的部分。

If any declaration before your structure declaration also contains an identifier named "type" then the rest of the identifiers will use the letter casing of that first one. The most unexpected case is when it is the name of a method parameter, most typically written in lower-case. Bummer if "Type" is the name of, say, a property, it will be renamed to "type". The crude part.

唯一的解决方法是使用更具体的名称,而不会发生冲突。

The only workaround is to use a more specific name that doesn't clash.

这篇关于从C#导出COM组件时的命名问题(小写/大写)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 21:59