Using COM objects

Can I use COM objects and their methods in a sevice application written using C SDK ie not using MFC in VC++ 6.0?
jas123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nils pipenbrinckCommented:
Sure you can.

You don't need MFC do to work with COM-Objects. (I'm not sure about the service applications, but they shouldn't cause problems).

I have a small example source which creates a IDirectDraw Interface and gets the display size. It might not work with WinNT (I'n not sure about that), but it shows that com-objects work.

btw.. I wanted to give you a short example, but I was unsure which COM-Object is easy to use.. since I work with DirectX most of the time I tried it with DDRAW.

I hope that answers your question,

  Nils Pipenbrinck

---- stupid program begins here -----

#include <windows.h>
#include <ddraw.h>
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  IDirectDraw *dd;
  if (DirectDrawCreate(0,&dd, 0)==DD_OK)
  {
    DDSURFACEDESC ddsd;
    memset (&ddsd, 0, sizeof (ddsd));
    ddsd.dwSize = sizeof (DDSURFACEDESC);
    dd->GetDisplayMode (&ddsd);
    char temp[256];
    wsprintf (temp, "display size from ddraw = %d * %d",
    ddsd.dwWidth, ddsd.dwHeight);
    dd->Release();
    MessageBox (0, temp, "infos from a com-object", 0);
  }
  return 0;
}





0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jas123Author Commented:
I am using only C language ie. I do not have Winmain but the method main().


When I try to declare a pointer of a com object say IDBConnect *Connect;

while compilation it gives me an error saying that
'IDBConnect' : illegal use of this type as an expression
0
jas123Author Commented:
Are there any settings to be made or are the lib files or the dll to be copied anywhere?
0
jas123Author Commented:
I have solved the above problem.

But now when I try to call a method say Connect of the object then while compilation I get an error saying that
'Connect' : is not a member of 'IDBConnect' where I have IDBConnect *Con = 0;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.