Problem with regular C Class in ATL
-
Sorry if this seems like a dumb question but ... In the past I've built ATL components using only regular COM CoClasses. Now I am working on a wrapper component to allow some legacy C++ code to be called via COM. I've created just the basic standard ATL DLL framework with a single method that delegates the actual implementation to some legacy C++ code that I have. I pass in two strings which are source and target file paths. Then the legacy code is to be called to perform the actual work. But I cannot call a method on the standard C++ class because even though I create a class instance, the compiler throws a C2228 error during a method call. My ATL code looks something like: ********************************************************************************************** STDMETHODIMP CMyWrapper::ExecuteLegacyParse(BSTR bstrSource, BSTR bstrTarget) { //Convert the input BSTRs to ANSI C Strings because ANSI Win32 API calls are required USES_CONVERSION; char* lpszSource = OLE2A(bstrSource); char* lpszTarget = OLE2A(bstrTarget); //So far, so good! //Create an instance of CLegacyParse class //No error occurs when creating the legacy CLegacyParse class which is a standard //C++ class CLegacyParse LegacyParse(); //So far, so good! //The following line will not compile! I get a C2228 error - object on the left //side of the operand must be a class/struct blah blah blah ... int nResult = LegacyParse.ParseDocument(lpszSource, lpszTarget); return S_OK; } ********************************************************************************************** So my question is, why am I able to create an instance of my CLegacyParse class (again, this is just a generic C++ class, not a CoClass), but I am not able to call a method because the compiler does not recognize my class instance reference, even though it allows the prerequisite instantiation of the C++ legacy class with no errors or warnings??? Is this a problem of COM _stdcall not being compatible with ordinary _cdecl call or something else? Also, if I just cut and paste my legacy C++ methods into the wrapper COM CoClass as non-com private methods, and supply the function prototypes in the header, the component works fine. But I don't want to do this because it obfuscates the fact that I simply want to create a COM callable wrapper around existing legacy C++ classes. PLus I also want to understand exactly why it does not wor