Click here to Skip to main content
16,004,882 members
Home / Discussions / COM
   

COM

 
GeneralRe: GetObject() failed Pin
Jörgen Sigvardsson25-Oct-04 8:38
Jörgen Sigvardsson25-Oct-04 8:38 
GeneralRe: GetObject() failed Pin
liyang yu25-Oct-04 8:47
liyang yu25-Oct-04 8:47 
GeneralRe: GetObject() failed Pin
Jörgen Sigvardsson25-Oct-04 8:51
Jörgen Sigvardsson25-Oct-04 8:51 
GeneralRe: GetObject() failed Pin
liyang yu25-Oct-04 8:56
liyang yu25-Oct-04 8:56 
Generalon COM in .NET Pin
ppp00125-Oct-04 1:21
ppp00125-Oct-04 1:21 
General"Interface not registered" with win XP Pin
sanouk24-Oct-04 22:19
sanouk24-Oct-04 22:19 
GeneralRe: "Interface not registered" with win XP Pin
geo_m19-Nov-04 3:27
geo_m19-Nov-04 3:27 
Generalbasic question about COM Pin
liyang yu23-Oct-04 9:14
liyang yu23-Oct-04 9:14 
I am writing a very simple local COM server (exe), which has a Car class, a CarClassFactory, also a simple idl, everything goes well until the WinMain() file which provides the housing for the coclass and class factory, vC6.00 keeps saying the following:

Deleting intermediate files and output files for project 'CarCOMExe - Win32 Debug'.
--------------------Configuration: CarCOMExe - Win32 Debug--------------------
Creating Type Library...
Processing F:\COM\CarCOMExe\CarCOMExeTypeInfo.idl
CarCOMExeTypeInfo.idl
Processing F:\Microsoft Visual Development\Microsoft Visual Studio\VC98\INCLUDE\oaidl.idl
oaidl.idl
Processing F:\Microsoft Visual Development\Microsoft Visual Studio\VC98\INCLUDE\objidl.idl
objidl.idl
Processing F:\Microsoft Visual Development\Microsoft Visual Studio\VC98\INCLUDE\unknwn.idl
unknwn.idl
Processing F:\Microsoft Visual Development\Microsoft Visual Studio\VC98\INCLUDE\wtypes.idl
wtypes.idl
Compiling...
StdAfx.cpp
Compiling...
Car.cpp
CarClassFactory.cpp
CarCOMExe.cpp
f:\com\carcomexe\carclassfactory.h(13) : error C2504: 'IClassFactory' : base class undefined
f:\com\carcomexe\carclassfactory.h(19) : error C2061: syntax error : identifier 'REFIID'
f:\com\carcomexe\carclassfactory.h(25) : error C2061: syntax error : identifier 'LPUNKNOWN'
F:\COM\CarCOMExe\CarCOMExe.cpp(32) : error C2065: 'CoInitialize' : undeclared identifier
F:\COM\CarCOMExe\CarCOMExe.cpp(36) : error C2065: 'ITypeLib' : undeclared identifier
F:\COM\CarCOMExe\CarCOMExe.cpp(36) : error C2065: 'pTLib' : undeclared identifier
F:\COM\CarCOMExe\CarCOMExe.cpp(36) : error C2106: '=' : left operand must be l-value
F:\COM\CarCOMExe\CarCOMExe.cpp(37) : error C2065: 'LoadTypeLibEx' : undeclared identifier
F:\COM\CarCOMExe\CarCOMExe.cpp(37) : error C2065: 'REGKIND_REGISTER' : undeclared identifier
F:\COM\CarCOMExe\CarCOMExe.cpp(38) : error C2227: left of '->Release' must point to class/struct/union
F:\COM\CarCOMExe\CarCOMExe.cpp(48) : error C2065: 'CoRegisterClassObject' : undeclared identifier
F:\COM\CarCOMExe\CarCOMExe.cpp(48) : error C2065: 'IClassFactory' : undeclared identifier
F:\COM\CarCOMExe\CarCOMExe.cpp(48) : error C2059: syntax error : ')'
F:\COM\CarCOMExe\CarCOMExe.cpp(61) : error C2065: 'CoRevokeClassObject' : undeclared identifier
F:\COM\CarCOMExe\CarCOMExe.cpp(65) : error C2065: 'CoUninitialize' : undeclared identifier
locks.cpp
Generating Code...
Error executing cl.exe.
Creating browse info file...

CoCarEXE.exe - 15 error(s), 0 warning(s)

as you can sees, it keeps saying that IClassFactory is undefined, but the CarClassFactory.cpp compiles well. CarClassFactory.h is very simple:

#define CarClassFactory_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <windows.h>

class CarClassFactory : public IClassFactory
{
public:
	CarClassFactory();
	virtual ~CarClassFactory();

	// IUnknown
	STDMETHODIMP QueryInterface(REFIID riid,void** pIFace);
	STDMETHODIMP_(ULONG)AddRef();
	STDMETHODIMP_(ULONG)Release();

	// IClassFactory
	STDMETHODIMP LockServer(BOOL fLock);
	STDMETHODIMP CreateInstance(LPUNKNOWN pUnkOuter,REFIID riid,void** ppv);

private:

	ULONG m_refCount;

};
#endif


and CarCOMExe.cpp is as follows:

#include "stdafx.h"
#include "CarCOMExeTypeInfo_i.c"	// MIDL file
#include "CarClassFactory.h"		// MIDL file
#include <string.h>


// Our global counter for locks & active objects.
DWORD g_allLocks;


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	// Init COM.
	CoInitialize(NULL); 	

	// Let's register the type lib.
	// to get the 'free' type library marsahler.
	ITypeLib* pTLib = NULL;
	LoadTypeLibEx(L"CarCOMExeTypeInfo.tlb", REGKIND_REGISTER, &pTLib);
	pTLib->Release();
	
	// Let's see if we were started by SCM.
	if(strstr(lpCmdLine, "/Embedding") || strstr(lpCmdLine, "-Embedding"))
	{
		// Create the Car class object.
		CarClassFactory carClassFactory;

		// Register the Car Factory.
		DWORD regID = 0;
		CoRegisterClassObject(CLSID_Car, (IClassFactory*)&carClassFactory, 
							  CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, ®ID);

		// Now just run until a quit message is sent,
		// in responce to the final release.
		MSG ms;
		while(GetMessage(&ms, 0, 0, 0))
		{
			TranslateMessage(&ms);
			DispatchMessage(&ms);
		}

		// All done, so remove class object.
		CoRevokeClassObject(regID);	
	}

	// Terminate COM.
	CoUninitialize();	
	MessageBox(NULL, "Server is dying", "EXE Message!", MB_OK | MB_SETFOREGROUND);
	return 0;
}


Really frustrated, can some one give me some help?

Thanks!!
GeneralRe: basic question about COM Pin
Anonymous23-Oct-04 16:00
Anonymous23-Oct-04 16:00 
GeneralRe: basic question about COM Pin
liyang yu23-Oct-04 16:38
liyang yu23-Oct-04 16:38 
GeneralRe: basic question about COM Pin
liyang yu23-Oct-04 16:40
liyang yu23-Oct-04 16:40 
GeneralRe: basic question about COM - the answer is here!! Pin
liyang yu23-Oct-04 17:14
liyang yu23-Oct-04 17:14 
GeneralRe: basic question about COM - the answer is here!! Pin
User 21559725-Oct-04 19:59
User 21559725-Oct-04 19:59 
GeneralRe: basic question about COM - the answer is here!! Pin
liyang yu26-Oct-04 8:18
liyang yu26-Oct-04 8:18 
GeneralRe: basic question about COM Pin
vikramlinux26-Oct-04 20:05
vikramlinux26-Oct-04 20:05 
GeneralMaximum Rows/Columns in an Excel Worksheet Pin
moredip21-Oct-04 8:11
moredip21-Oct-04 8:11 
GeneralRe: Maximum Rows/Columns in an Excel Worksheet Pin
moredip21-Oct-04 8:20
moredip21-Oct-04 8:20 
GeneralRe: Maximum Rows/Columns in an Excel Worksheet Pin
darkbyte11-Nov-04 10:26
darkbyte11-Nov-04 10:26 
GeneralI can't get the body of the mail Pin
ting66820-Oct-04 21:19
ting66820-Oct-04 21:19 
GeneralGet Recipients of a mail inbox using mapi Pin
ting66820-Oct-04 21:09
ting66820-Oct-04 21:09 
GeneralExcel Project DLL's Pin
Jeremy Ouellette20-Oct-04 9:28
Jeremy Ouellette20-Oct-04 9:28 
GeneralMAPI thows Cannot change thread mode after it is set exception Pin
Gavin Jeffrey20-Oct-04 4:22
Gavin Jeffrey20-Oct-04 4:22 
GeneralWord Automation - set underline font Pin
onyx19-Oct-04 20:55
onyx19-Oct-04 20:55 
Generalshell extension dll not loaded for Win98. Pin
Abhi Lahare18-Oct-04 21:18
Abhi Lahare18-Oct-04 21:18 
Generalserial port communication Pin
Anonymous18-Oct-04 13:50
Anonymous18-Oct-04 13:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.