Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. COM
  4. why to put extern C before const IID?

why to put extern C before const IID?

Scheduled Pinned Locked Moved COM
c++comquestionlearning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lane Yu
    wrote on last edited by
    #1

    I'm a beginner of COM. I just saw some sample codes: DictionaryObj.cpp extern "C" const IID IID_Dictionary = { 0x54bf6568, 0x1007, 0x11d1, { 0xb0, 0xaa, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00} } ; I don't understand the purpose of extern "C". Since IID_Dictionary will not be exported, why to use this prefix? Thanks.

    M 1 Reply Last reply
    0
    • L Lane Yu

      I'm a beginner of COM. I just saw some sample codes: DictionaryObj.cpp extern "C" const IID IID_Dictionary = { 0x54bf6568, 0x1007, 0x11d1, { 0xb0, 0xaa, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00} } ; I don't understand the purpose of extern "C". Since IID_Dictionary will not be exported, why to use this prefix? Thanks.

      M Offline
      M Offline
      Marco M
      wrote on last edited by
      #2

      The IID has to be visible across all .obj files that are using it. Say IID_IDictionary is defined in fileOne.cpp (which when compiled generates fileOne.obj) And in FileTwo.cpp you are referencing IID_IDictionary, the linker will error out unless the IID has the extern "C", as this extern "C" basically tells the linker that the IID is defined in another obj file. Marco M.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups