Click here to Skip to main content
16,005,222 members
Home / Discussions / COM
   

COM

 
QuestionThe problem about Excel automation add-ins. Pin
dreamwinter12-Oct-05 20:49
dreamwinter12-Oct-05 20:49 
Question0x800401fb Pin
Joseph Hayes12-Oct-05 20:39
Joseph Hayes12-Oct-05 20:39 
AnswerRe: 0x800401fb Pin
Roger Stoltz12-Oct-05 20:59
Roger Stoltz12-Oct-05 20:59 
AnswerRe: 0x800401fb Pin
JonEngle26-Oct-05 18:39
JonEngle26-Oct-05 18:39 
QuestionIClassFactory::CreateInstance() Pin
odiesback12-Oct-05 6:50
odiesback12-Oct-05 6:50 
AnswerRe: IClassFactory::CreateInstance() Pin
User 21559712-Oct-05 11:57
User 21559712-Oct-05 11:57 
AnswerRe: IClassFactory::CreateInstance() Pin
rwestgraham12-Oct-05 12:38
rwestgraham12-Oct-05 12:38 
GeneralRe: IClassFactory::CreateInstance() Pin
odiesback13-Oct-05 4:32
odiesback13-Oct-05 4:32 
Thanks for your repplies:

I am studying COM from "Developer's Workshop to COM and ATL 3.0"
and the code in question is presented by the author for VC6.0 and I am
using VC7.0.

The book uses the call to the IClassFactory and then calls CreateInstance(), which
refuses to run. After trying go get it to work I replace for a call
to CoCreateInstance(). Not even the code supplied by the CD aruns.

this is the code:
----------------------------------------------------
#include <iostream.h>

#include "interfaces.h"
#include "iid.h"


int main()
{
// Initialize COM sub system
CoInitialize(NULL);

// Declare all interfaces you are going to use
IClassFactory* pCarFact = NULL;
ICreateCar* pICreateCar = NULL;
IStats* pIStats = NULL;
IEngine* pIEngine = NULL;

// Declare the return type HRESULT
HRESULT hr;

// Screen page Header
cout << "\n*****************************************************";
cout << "\n** T H E A M A Z I N G C O C A R C L I E N T **";
cout << "\n*****************************************************\n\n";;


// Grab the IClassFactory pointer from CoCarFactory
hr = CoGetClassObject(CLSID_CoCar, CLSCTX_INPROC_SERVER, NULL,
IID_IClassFactory, (void**)&pCarFact);


hr = CoCreateInstance(CLSID_CoCar, NULL, CLSCTX_INPROC_SERVER, IID_ICreateCar,
(void**)&pICreateCar);

//-------> hr is 0 coming out of the expression above
/*
Sigh | :sigh: // THE PROGRAM COMPILES BUT IT CRASHES IF USING the IClassFactory pointer
// Call CreateInstance() from the Class Fatory pointer, and ask for IID_ICreate from the
// CoCar
hr = pCarFact->CreateInstance(NULL, IID_ICreateCar, (void**)&pICreateCar);

// Once you used the CoClassFactory pointer, release it.
pCarFact->Release();
*/
// Exercise ICreateCar
if(SUCCEEDED(hr))
{
BSTR name = SysAllocString(L"Odie Silva");
pICreateCar->SetPetName(name);
SysFreeString(name);

pICreateCar->SetMaxSpeed(100);

// Find IStats
hr = pICreateCar->QueryInterface(IID_IStats, (void**)&pIStats);

// Now can release ICreateCar
pICreateCar->Release();
}

if(SUCCEEDED(hr))
{
// Display properties
pIStats->DisplayStats();

// Switch hr to IEngine interface using IStats* (can also use IUnknown*)
hr = pIStats->QueryInterface(IID_IEngine, (void**)&pIEngine);
}

// If successful run the IEngine
if(SUCCEEDED(hr))
{
int curSpd = 0;
int maxSp = 0;
pIEngine->GetMaxSpeed(&maxSp);
do
{
pIEngine->SpeedUp();
pIEngine->GetCurSpeed(&curSpd);
cout << "\n\n Speed is: " << curSpd << endl;
}while(curSpd < maxSp);

// Convert BSTR to char array
char buff[80];
BSTR bstr;
pIStats->GetPetName(&bstr);

WideCharToMultiByte(CP_ACP, NULL, bstr, -1, buff, 80, NULL, NULL);
cout << "\n" << buff << " has blown up! Lead foot!" << endl;

// Final clean up
SysFreeString(bstr);
if(pIEngine)
pIEngine->Release();

if(pIStats)
pIStats->Release();
}

// Unload COM system
CoUninitialize();


return 0;
}
AnswerRe: IClassFactory::CreateInstance() Pin
odiesback24-Oct-05 5:04
odiesback24-Oct-05 5:04 
QuestionActive Activex in the IDE Pin
lgaudouen11-Oct-05 7:21
lgaudouen11-Oct-05 7:21 
AnswerRe: Active Activex in the IDE Pin
vishalmore13-Oct-05 22:34
vishalmore13-Oct-05 22:34 
QuestionCreating only one instance Pin
ChemmieBro11-Oct-05 5:14
ChemmieBro11-Oct-05 5:14 
QuestionCreate a simple COM application Pin
Member 98603511-Oct-05 0:46
Member 98603511-Oct-05 0:46 
AnswerRe: Create a simple COM application Pin
dreamwinter19-Oct-05 22:26
dreamwinter19-Oct-05 22:26 
QuestionRetrive COM Interfaces Pin
benjamin2310-Oct-05 16:35
benjamin2310-Oct-05 16:35 
AnswerRe: Retrive COM Interfaces Pin
vishalmore11-Oct-05 1:54
vishalmore11-Oct-05 1:54 
AnswerRe: Retrive COM Interfaces Pin
User 21559711-Oct-05 8:37
User 21559711-Oct-05 8:37 
GeneralRe: Retrive COM Interfaces Pin
benjamin2311-Oct-05 16:53
benjamin2311-Oct-05 16:53 
GeneralRe: Retrive COM Interfaces Pin
User 21559711-Oct-05 21:03
User 21559711-Oct-05 21:03 
QuestionOPC Pin
Marc Soleda10-Oct-05 4:29
Marc Soleda10-Oct-05 4:29 
Questioninsert a object when the activex container Initializing Pin
ccto6-Oct-05 6:46
ccto6-Oct-05 6:46 
QuestionWebBrowserControl &amp; DISPID_AMBIENT_DLCONTROL Pin
AlexR1236-Oct-05 6:28
AlexR1236-Oct-05 6:28 
QuestionSafeArrayCreate(Ex) Failure.... Pin
morenz6-Oct-05 2:46
morenz6-Oct-05 2:46 
AnswerRe: SafeArrayCreate(Ex) Failure.... Pin
David_Leikis6-Oct-05 5:17
David_Leikis6-Oct-05 5:17 
GeneralRe: SafeArrayCreate(Ex) Failure.... Pin
morenz7-Oct-05 0:21
morenz7-Oct-05 0:21 

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.