Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'CComPtr' : use of class template requires template argum

Status
Not open for further replies.

sunijam

Technical User
Jul 15, 2005
3
US
Hello folks,
I am newbie to ATL/COM programming!!!! I am trying to add a COM dll in Visual C++ for PocketPC 2002. So i took a simple hello world program and tried to instantiate an object of one of the interfaces in the dll. I am not able to compile. Looks like I am getting an error in trying to initialize using CComPtr. Would really appreciate your help.!!!!

I have attached the code here and also the compile errors. I am hard pressed with time to finish this. I am not able to proceed further. Would really appreciate any help you can give.

I have also included atlbase.h
CComPtr <IReader> pMobileObj;
// creating a MobileObj object
HRESULT hr =pMobileObj.CoCreateInstance(CLSID_Reader);

Compile errors:
Test.cpp
C:\SMM6.4\POCKETPC\VC++\Test\Test.cpp(159) : error C2065: 'IReader' : undeclared identifier
C:\SMM6.4\POCKETPC\VC++\Test\Test.cpp(159) : error C2955: 'CComPtr' : use of class template requires template argument list
C:\Windows CE Tools\wce300\Pocket PC 2002\atl\include\atlbase.h(674) : see declaration of 'CComPtr'
C:\SMM6.4\POCKETPC\VC++\Test\Test.cpp(159) : error C2133: 'pMobileObj' : unknown size
C:\SMM6.4\POCKETPC\VC++\Test\Test.cpp(159) : error C2512: 'CComPtr' : no appropriate default constructor available
C:\SMM6.4\POCKETPC\VC++\Test\Test.cpp(159) : error C2262: 'pMobileObj' : cannot be destroyed
C:\SMM6.4\POCKETPC\VC++\Test\Test.cpp(161) : error C2065: 'CLSID_Reader' : undeclared identifier

-sunijam
 
Thank you so much cdraycott. That helped me understand why I am getting this error. But I still seem to get a serious of these errors. I am not able to understand why. I think I am missing some dll's or libraries.
Have you come across this situation?

This is the serious of errors:
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(49) : error C2065: 'IConverterPtr' : undeclared identifier
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(49) : error C2146: syntax error : missing ';' before identifier 'cnv'
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(49) : error C2065: 'cnv' : undeclared identifier
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(50) : error C2065: 'gt' : undeclared identifier
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(50) : error C2113: pointer can only be subtracted from another pointer
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(50) : error C2065: 'IntToString' : undeclared identifier
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(170) : error C2065: 'ITagReader' : undeclared identifier
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(170) : error C2955: 'CComPtr' : use of class template requires template argument list
C:\Windows CE Tools\wce300\Pocket PC 2002\atl\include\atlbase.h(674) : see declaration of 'CComPtr'
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(170) : error C2133: 'pMobileReader' : unknown size
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(170) : error C2512: 'CComPtr' : no appropriate default constructor available
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(170) : error C2262: 'pMobileReader' : cannot be destroyed
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(172) : error C2065: 'CLSID_TagReader' : undeclared identifier
 
sunijam,

i would need to see source code here. It looks like there may be some syntactical errors here as well as errors relating to CComPtr.
 
Hello cdraycott,
here is the source code.

This is the code I added in StdAfx.h
#define ST_IGNORE_COM_EXCEPTIONS
#include "STUtil.h"

void _com_issue_error(HRESULT hr);
void _com_issue_errorex(HRESULT hr, IUnknown* pUnkn, REFIID riid);
#import "c:\Windows\SaviReader.dll" named_guids, no_namespace, raw_interfaces_only

This is what I have added in main file.cpp.
/*************************************************************
// I get an error in error C2065: 'IConverterPtr' : undeclared identifier after adding #define ST_IGNORE_COM_EXCEPTIONS.
/**************************************************************

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;


IConverterPtr cnv(_T("Test.Converter"));
_bstr_t str = cnv-&gt;IntToString(46);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TEST);

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}


/**************************************************************
// I get the following error from this piece of code.
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(170) : error C2065: 'ITagReader' : undeclared identifier
C:\SMM6.4\PocketPC\VC++\Test\Test.cpp(170) : error C2955: 'CComPtr' : use of class template requires template argument list
C:\Windows CE Tools\wce300\Pocket PC 2002\atl\include\atlbase.h(674) : see declaration of 'CComPtr'
/****************************************************************

void DoMobileReader()
{

CComPtr <ITagReader> pMobileReader;
// creating a MobileReader object
HRESULT hr = pMobileReader.CoCreateInstance(CLSID_TagReader);
if(SUCCEEDED(hr))
{
printf(" successful in object creation\n");
}
}

void _com_issue_error(HRESULT hr)
{
//Insert a custom implementation, such as the following.
TRACE( _T("Caught unhandled COM exception!\n") );
}

void _com_issue_errorex(HRESULT hr, IUnknown* pUnkn, REFIID riid)
{
//Insert a custom implementation, such as the following.
TRACE( _T("Caught unhandled COM exception!\n") );
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top