如何清除以下visual studio错误? [英] How to clear the following visual studio error?

查看:337
本文介绍了如何清除以下visual studio错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c ++代码是 -

The c++ code is -

// SimpleCom.cpp : Implementation of CSimpleCom

/*#include "C:\Users\georget\Documents\Visual Studio 2012\Projects\Pro1\Pro1\stdafx.h"
#include "C:\Users\georget\Documents\Visual Studio 2012\Projects\Pro1\Pro1\SimpleCom.h"
#include "stdafx.h"*/
#include "stdafx.h"
#include "SimpleCom.h"













// CSimpleCom

[ClassInterface(ClassInterfaceType::AutoDispatch)]
       [ProgId(S"InteropSample::MyClass")]

STDMETHODIMP CSimpleCom::add(LONG a1, LONG a2, LONG* r)
{
	// TODO: Add your implementation code here
	*r=a1+a2;
	return S_OK;
}



显示的错误 -


the error it shows-

Error   1   error C2337: 'ClassInterface' : attribute not found 
Error   2   error C2653: 'ClassInterfaceType' : is not a class or namespace name   
Error   3   error C2065: 'AutoDispatch' : undeclared identifier c:\users\georget\documents\visual studio 2012\projects\pro1\pro1\simplecom.cpp  13  1   Pro1
Error   4   error C2337: 'ProgId' : attribute not found 
Error   5   error C3921: Use of S-prefixed strings requires /clr:oldSyntax command line option  
Error   6   error C1903: unable to recover from previous error(s); stopping compilation

Can anyone suggest how to correct it?

推荐答案

请参阅我对该问题的评论。



现在,正确的属性名称是 System.Runtime :: InteropServices :: ClassInterfaceAttribute 并且它是您尝试的参数use的类型为 System.Runtime.InteropServices.ClassInterfaceAttribute

您没有使用这些全名(ClassInterfaceAttribute通常缩写为 ClassInterface应用属性的地方,并且您没有使用指令在中规定命名空间。所以,你会期待什么?



请参阅:

https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.classinterfaceattribute%28v= vs.100%29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.classinterfacetype%28v=vs.110%29。 aspx [ ^ ]。



只需正确编写所有内容。学习程序集及其引用,输入命名和命名空间。



-SA
Please see my comment to the question.

Now, proper attribute name is System.Runtime::InteropServices::ClassInterfaceAttribute and it's parameter you tried to use is of the type System.Runtime.InteropServices.ClassInterfaceAttribute.
You did not use those full names ("ClassInterfaceAttribute" is usually shorted to "ClassInterface" where the attribute is applied), and you did not prescribe the namespace in using directive. So, what would you expect?

Please see:
https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.classinterfaceattribute%28v=vs.100%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.classinterfacetype%28v=vs.110%29.aspx[^].

Just write everything properly. Learn assemblies and their referencing, type naming and namespaces.

—SA


这篇关于如何清除以下visual studio错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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