-
February 17th, 2023, 06:05 AM
#1
COM tutorial
Hello All,
I was trying to implement the following COM tutorial using the visual studio 2022.
https://www.codeguru.com/soap/step-b...utorial/#Intro
But getting some issues.
Also the
Download source – 114 Kb
Download demo project – 101 Kb
buttons arent working
Could some experts, please refine the steps as per visual studio 2022. I just want to implement the bare minimal, for my own understanding.
Thanks a lot
pdk
Last edited by pdk5; February 17th, 2023 at 06:17 AM.
-
February 17th, 2023, 06:58 AM
#2
Re: COM tutorial
Did you try to download source or/and demo project?
I cannot download either of them. I only get the
404 Not Found error code.
Victor Nijegorodov
-
February 17th, 2023, 08:31 AM
#3
Re: COM tutorial
Thankyou very much Victor for looking into this.
Yes, even i couldnot download them, as i mentioned in my post. So I tried to cut paste the code to my VS and compiled. I could use the MIDL, and could generate the files from the IDL, but it is complaining later
-
February 17th, 2023, 09:30 AM
#4
Re: COM tutorial
I found one issue and fixed it:
In the AddObj.cpp, the static_cast target type was missing and I added the following and made that file compile.
Code:
HRESULT __stdcall CAddObj::QueryInterface(
REFIID riid,
void** ppObj)
{
if (riid == IID_IUnknown)
{
delete this;
*ppObj = static_cast<IUnknown *>(this);
AddRef();
return S_OK;
}
if (riid == IID_IAdd)
{
*ppObj = static_cast<IAdd *>(this);
AddRef();
return S_OK;
}
//
//if control reaches here then , let the client know that
//we do not satisfy the required interface
//
*ppObj = NULL;
return E_NOINTERFACE;
}//QueryInterface method
But now it is complaining in the "AddObjFactory.cpp", looks like I need to add the The AddRef, Release and QueryInterface methods like to that of class CAddObj , as per the tutorial. I added these functions:
Code:
HRESULT __stdcall CAddFactory::QueryInterface(
REFIID riid,
void** ppObj)
{
if (riid == IID_IUnknown)
{
delete this;
*ppObj = static_cast<IUnknown*>(this);
AddRef();
return S_OK;
}
if (riid == IID_IAdd)
{
*ppObj = static_cast<IAdd*>(this);
AddRef();
return S_OK;
}
//
//if control reaches here then , let the client know that
//we do not satisfy the required interface
//
*ppObj = NULL;
return E_NOINTERFACE;
}//QueryInterface method
ULONG __stdcall CAddFactory::AddRef()
{
return InterlockedIncrement(&m_nRefCount);
}
ULONG __stdcall CAddFactory::Release()
{
long nRefCount = 0;
nRefCount = InterlockedDecrement(&m_nRefCount);
if (nRefCount == 0) delete this;
return nRefCount;
}
Not sure if its correct. If somebody makes the link with the project downloads working i can crosscheck my implementation
-
February 17th, 2023, 09:47 AM
#5
Re: COM tutorial
Currently Im getting compile error, CLSID_AddObject not defined in the Exports.cpp file. :::
I guess I know this answer, as I need to register the COM object.
As per the instructions, the registering should happen when the project is run.
It will be very helpful, if the owners of that document in this forum, please correct the link
Last edited by pdk5; February 18th, 2023 at 09:23 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|