Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The c++ code is -
C++
// 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"




C++
// 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?
Posted
Updated 6-Aug-15 20:37pm
v2
Comments
Sergey Alexandrovich Kryukov 7-Aug-15 2:32am    
It looks like you are mixing C++/CLI with C++ (ATL, COM, etc.). I'm not saying you should not do it, but I'm not sure if you really need it. Now, you simply did not use correct type names. And you don't have "using" for them. Finally, you might not reference their assembly.
—SA
Jochen Arndt 7-Aug-15 2:36am    
The name space is missing. At least
using namespace System::Runtime::InteropServices;
should be present (may be more name spaces).

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900