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
  1. Home
  2. General Programming
  3. COM
  4. calling COM using CreateObject ( late bind )

calling COM using CreateObject ( late bind )

Scheduled Pinned Locked Moved COM
comannouncement
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.
  • V Offline
    V Offline
    vineeshV
    wrote on last edited by
    #1

    hi i have a COM definitions as interface IMyInterface : IDispatch { [id(1), helpstring("method SetUserTicket")] HRESULT SetUserTicket([in] BSTR bstrTicket, [out,retval] VARIANT *varRetVal); }; [ uuid(), version(1.0), helpstring("My Type Library") ] library MYLib { uuid(), helpstring("My Class") coclass MyApis { [default] interface IMyInterface; }; }; The output dll was formed as MY.dll using reference add the following line works in vb dim aa as MYLib.MyApis aa.SetUserTicket() But when using CreateObject function as CreateObject("MYLib.MyApis","") it was not working . Is the function call is correct . or i need to pass any other names to the function.

    vineesh

    M 1 Reply Last reply
    0
    • V vineeshV

      hi i have a COM definitions as interface IMyInterface : IDispatch { [id(1), helpstring("method SetUserTicket")] HRESULT SetUserTicket([in] BSTR bstrTicket, [out,retval] VARIANT *varRetVal); }; [ uuid(), version(1.0), helpstring("My Type Library") ] library MYLib { uuid(), helpstring("My Class") coclass MyApis { [default] interface IMyInterface; }; }; The output dll was formed as MY.dll using reference add the following line works in vb dim aa as MYLib.MyApis aa.SetUserTicket() But when using CreateObject function as CreateObject("MYLib.MyApis","") it was not working . Is the function call is correct . or i need to pass any other names to the function.

      vineesh

      M Offline
      M Offline
      Mike the Red
      wrote on last edited by
      #2

      Did you create all the registry entries for your COM Server? When you add a reference to the .dll, VB reads the .dll and accesses it directly. When you use CreateObject(ObjectID), COM looks up the ObjectID in the registry to get its GUID and then looks up the GUID in the registry to find your .dll and its type library. To be able to use CreateObject(), there are several registry entries needed. Your library is MY.dll, so let's call the typelib MY.tlb. These are the minimum entries you need: HKEY_CLASSES_ROOT\\MYLib.MyApis = "My COM Server" _(Friendly name)_ HKEY_CLASSES_ROOT\\MYLib.MyApis\\CLSID = GUID_of_Class_MyApis HKEY_CLASSES_ROOT\\CLSID\\GUID_of_Class_MyApis = "My COM Server" _(Friendly name)_ HKEY_CLASSES_ROOT\\CLSID\\GUID_of_Class_MyApis\\InProcServer32 = "[PATH]\MY.dll" ThreadingModel = "Apartment" (This one is a value under InProcServer32, not a key) HKEY_CLASSES_ROOT\\CLSID\\GUID_of_Class_MyApis\\ProgID = "MYLib.MyApis" HKEY_CLASSES_ROOT\\CLSID\\GUID_of_Class_MyApis\\TypeLib = GUID_of_TypeLib HKEY_CLASSES_ROOT\\CLSID\\GUID_of_Class_MyApis\\Version = "1.0" HKEY_CLASSES_ROOT\\Interface\\GUID_of_Interface_IMyInterface = "My COM Interface" _(Friendly name)_ HKEY_CLASSES_ROOT\\Interface\\GUID_of_Interface_IMyInterface\\TypeLib = GUID_of_TypeLib HKEY_CLASSES_ROOT\\Interface\\GUID_of_Interface_IMyInterface\\Version = "1.0" HKEY_CLASSES_ROOT\\TypeLib\\GUID_of_TypeLib HKEY_CLASSES_ROOT\\TypeLib\\GUID_of_TypeLib\\1.0 = "My COM Server Type Library" _(Friendly name)_ HKEY_CLASSES_ROOT\\TypeLib\\GUID_of_TypeLib\\1.0\\0 HKEY_CLASSES_ROOT\\TypeLib\\GUID_of_TypeLib\\1.0\\0\\win32 = "[PATH]\MY.tlb" Technically there is a versioning issue here, so your \\GUID_of_Class_MyApis\\ProgID value should be "MYLib.MyApis.1" and then you'd create a VersionIndependentID key to associate "MYLib.MyApis" with "MYLib.MyApis.1"... but this isn't strictly necessary. Though you can create them by hand using RegEdit, all of these keys should be created in your DLL's DllRegisterServer() method and they should be deleted in your DLL's DllUnregisterServer() method, for use with RegSvr32.exe Hope this helps, MZR

      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