Win32 COM Programming in Pure C

I have a programming project that requires access to some lower layers of the Windows API (in particular, WASAPI). I am fairly experienced with higher-level programming languages ​​such as C #, Java, and PHP, and I know a little about C / C ++.

I would like to use C (not C ++) for this project, since C ++ is scary . After changing the C / C ++ settings of my project in Visual Studio to compile as C code, I noticed that any calls __uuidofwould not work, as they are C ++ specific.

My question is twofold:

  • Is it possible to write Win32 programs that use COM in pure C , and
  • If so, should you use pure C?
+5
source share
2 answers
  • Yes, you can use pure, clean C programs that use COM, in fact it was a common practice 10-15 years ago.

  • You do not use the service using C (as you already noticed). For instance. ATL provides great help when you run COM, and can help you avoid common errors.

If I were you, I would go for C ++, even if the threshold can be a little higher at first. Also get a book in the subject if you don't have one. There are many examples that can be found on the net, but it's nice to have something that takes you by hand, since COM programming is not for the faint of heart, regardless of whether you use C or C ++.

+4
source

COM ++ C-, "" , :

  • - ++, ( RAII idiom, , C/Win32); COM : COM . , COM- ++-, , .

  • - COM, , COM- (, ) IUnknown. COM. , COM, . (, ++ COM-, , .)

  • - , COM, - . MFC ATL, , COM . , CComPtr, , , , .

COM ++ - ++ Windows ++ , COM. COM-, ++, , / , .

, , C ( vtable ):

pUnk->lpVtbl->SomeMethod(pUnk, 42);

++ :

pUnk->SomeMethod(42);

→ lpVtbl , 'this' ( !) COM, , ?

, COM- - Inside COM - , ++, . , COM- "raw" QI, AddRef .. , , , , , . , COM- ++, - , ++, , . - , , - COM C.

+4

All Articles