.tlh 2机产生的是不同的 [英] .tlh generated on 2 machines is different

查看:122
本文介绍了.tlh 2机产生的是不同的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET的DLL里面有一些接口\它们暴露于COM类。在构建过程中一个.tlb文件生成,这TLB是由一些C ++ code引用。因此编译器生成.tlh文件为证:

I have a .NET dll which has some interfaces\classes which are exposed to com. during the build procedure a .tlb file is generated and this tlb is referenced by some c++ code. As a result the compiler generates a .tlh file for the tlb.

当我在本地运行生成的属性之一接口的一端与在TLH相应的方法不具有相同的名称。在.NET code的属性称为PropertyA最终被称为get_propertyA,而PropertyB结束了所谓的get_PropertyB。我都没眨一下,当发生这种情况,只是使用的方法,在TLH定义并承担一切都虎背熊腰,脚蹬鲂,但是当我comitted这些更改的构建没有为任何人工作,因为编译器生成的属性称为get_PropertyA和眼睑get_PropertyB(在propertyA通知的情况下不匹配)。

When I run the build locally one of the properties in one of the interfaces ends up with a corresponding method in the tlh which does not have the same name. The property in the .net code is called PropertyA end up being called get_propertyA, while PropertyB ends up called get_PropertyB. I didn't bat an eyelid when this happened, just used the method as defined in the tlh and assumed everything was hunky dory, however when I comitted these changes the build did not work for anyone else, as the compiler generated properties called get_PropertyA and get_PropertyB (notice case mismatch in propertyA).

在两台机器上生成的TLB文件是相同的(根据十六进制比较器),并都是由相同的编译器版本生成的TLH文件。

The tlb files generated on both machines are identical (according to a hex comparer) and the tlh files are both generated by the same compiler version.

做的构建过程创建TLB:regasm路径\到\ DLL \ MYDLL.DLL -tlb:路径\到\输出\ mydll.tlb

The build procedure creates the tlb by doing: regasm path\to\dll\Mydll.dll -tlb:path\to\output\mydll.tlb

为什么我的本地版本结束了与不正确的名称属性的任何想法?或者,我能做些什么来解决这个问题?

Any ideas why my local version ends up with a property with the incorrect name? Or what I can do to fix it?

更新:我读了tlbexp将使用字符串的第一个版本,它发现,并可以与一个重新编译改变。虽然我没有使用tlbexp,我想知道这是否是问题。我发现参数具有相同的名称作为我的方法(在其它方法),但在开始时的小写字母。所以,我更换了所有这一切。重新修建的,没有变化。所以我再改名为我的COM方法。重新修建,并得到了预期的缺少方法的错误。改名的方法回原来的名字,哎preSTO似乎固定。因为它现在似乎工作,我不能让它再失败,我不能尝试建议的解决方案,但我喜欢的命名思路的情况下发生这种情况在未来。

UPDATE: I read that tlbexp will use the first version of the string that it finds and that can change with a recompile. Although I'm not using tlbexp, I wondered if that was the problem. I found parameters with the same name as my method (in other methods) but with a lower case letter at the start. So I replaced all of those. Re-built, no change. SO I then renamed my COM method. Re-Built and got the expected missing method errors. Renamed the method back to the original name, and hey presto it seemed fixed. As it now seems to work and I can't get it to fail again I can't try out the suggested solutions, but I like the rename idea in case this happens in the future.

推荐答案

您可以使用的改名的属性中的导入的显式命名的属性。假设你有 propA ,有时变成 PropA PROPB 的有时会变成 PROPB 。总是有 PropA PROPB 使用的改名的如下:

You can use the rename attribute for the import to explicitly rename the properties. Say you have propA that sometimes becomes PropA and propB that sometimes becomes PropB. To always have PropA and PropB use rename as follows:

#import <library> rename( "propA", "PropA" ) rename( "propB", "PropB" )

使用这种谨慎 - 它会导致一个简单的文本替换该工程遇到的类型库中的任何标识。在某些情况下,它可能会导致难以调试不良副作用

Use this with care - it causes a simple text substitution that works for any identifiers it encounters in the type library. In some cases it can cause hard to debug undesired side effects.

这篇关于.tlh 2机产生的是不同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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