【发布时间】:2010-10-19 21:19:14
【问题描述】:
我有一个 .Net asm,其中有几个使用 [ComVisible(true)] 属性向 COM 公开的接口和类。我生成一个 tlb,然后在 C++ COM 组件内的 StdAdx 文件中引用它。奇怪的是,出于某种原因,即使非常基本的智能感知(用于 C++ 的 VS6)能够看到我的属性和方法,我也会收到编译器错误,指出它们不是成员。例如:
[Guid("88E58BE4-E0CB-4d1b-9553-A5431E7A0BEA")]
[ComVisible(true)]
public interface ISupplierPayment : IBusinessObjectPersist
{
String Comment
{
get;
set;
}
并且在c++中生成的tlh中:
struct __declspec(uuid("e94bd31e-327c-33c8-8a55-b693ccf1ed96"))
struct __declspec(uuid("e94bd31e-327c-33c8-8a55-b693ccf1ed96"))
ISupplierPayment : IDispatch
{
//
// Raw methods provided by interface
//
virtual HRESULT __stdcall get_Comment (
BSTR * pRetVal ) = 0;
最后是尝试在代码中使用它时的错误:
D:\MR...File.cpp(647):错误 C2039:“评论”:不是“ISupplierPayment”的成员 d:\mr...projectdir\release\TheDotNetClasses.tlh(758) :参见“ISupplierPayment”的声明
有什么想法我接下来应该看什么吗?如果它在 tlh 中并且智能感知识别它并且它在 tlb 上的 OLEView 中,我不确定可能有什么问题..提前感谢您查看
更新 相关问题的进一步示例: C#
[Guid("3BE93D52-86B7-42e6-BAE6-29037F6BC9C4")]
[ComVisible(true)]
public interface IDataStoreFactory
{
void TestMethod(String test);
C++ TLH
struct __declspec(uuid("3be93d52-86b7-42e6-bae6-29037f6bc9c4"))
IDataStoreFactory : IDispatch
{
//
// Raw methods provided by interface
//
virtual HRESULT __stdcall TestMethod (
BSTR dataStoreAssembly ) = 0;
void TestMethod(String test);
C++ 方法调用
spDataStoreFactory->TestMethod("test");
C++编译错误
'TestMethod' : 无法将参数 1 从 'char [5]' 转换为 'unsigned short *' 指向的类型是不相关的;转换需要 reinterpret_cast、C-style cast 或 function-style cast
咦!?这不是一个短的它是一个BSTR......现在很困惑
【问题讨论】:
-
哦,顺便说一句 - 这就是我创建我调用 TestMethod 的对象的方式:IDataStoreFactoryPtr spDataStoreFactory(__uuidof(DataStoreFactory));
标签: c# .net c++ com-interop