0

I'm working on a C++ DLL that uses an IDL file to talk to another program's API. I'm trying to call a function that's defined in the following way in the other program's .idl:

[propget, id(1014), helpstring("The user defined attribute on the feature using the name of the attribute")] HRESULT UserAttribute([in] BSTR attr_id, [out, retval] VARIANT *pVal);

This is my method call in the DLL:

VARIANT *res = udf->UserAttribute(BSTR("version"));

However, when I try to compile the program, I get this error:

1>ApplicationSink.cpp(378): error C2660: 'IFMFeature::GetUserAttribute' : function does not take 0 arguments

The line number is for the line I quoted above; also the line I quoted above is the only line where the UserAttribute method appears anywhere in the DLL. So I know the error isn't actually referring to another place in the code where I do call it without arguments. Also, I'm using many, many other functions from the API with no problem, so I don't think the issue is with the API generally. I've also written VB macros that have successfully used the UserAttribute function, so I know it works in at least some cases.

I'm calling UserAttribute, but the error is talking about GetUserAttribute -- could that be because it's doing some behind-the-scenes magic related to the fact that UserAttribute is defined as a propget function? There is no GetUserAttribute function defined in the API.

Does anyone know what's happening here and how I can fix it?

  • Have you tried calling it `GetUserAttribute`? C++ prepends a `Get` and `Put` for `propget` and `propput` definitions, but other languages like VB and C# can get and set such properties without Get/Set accessors, simply by referencing the property name. – djikay Jun 27 '14 at 17:21
  • Are you using the "#import" compiler directive to reference your interface? If it's the case, then yes there is some magic happening behind your back. You can look at the header that the compiler has generated for you in the Intermediate directory. The UserAttribute() method is likely to be implemented in terms of GetUserAttribute() to do the handling of the HRESULT return value. – erbi Jun 27 '14 at 18:00
  • Update: Thanks for your question, today I learned something new. In the generated header (.tlh), the import directive declares UserAttribute as an array with a special compiler attribute ("property") that handles the parameter as if they were indices. So in your code, you have the choice of using either: udf->UserAttribute[BSTR("version")]; or udf->GetUserAttribute(BSTR("version")); http://msdn.microsoft.com/en-us/library/yhfk0thd.aspx – erbi Jun 27 '14 at 18:31
  • Both udf->GetUserAttribute(BSTR("version")); and udf->UserAttribute[BSTR("version")]; worked. Thank you for your help! – khariifa Jun 27 '14 at 18:41

0 Answers0