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. How to call methods of an appobject directly?

How to call methods of an appobject directly?

Scheduled Pinned Locked Moved COM
helpquestionc++comtutorial
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.
  • R Offline
    R Offline
    Roozbeh69
    wrote on last edited by
    #1

    Hello everybody, I am a beginner in com programming, and i have a question: I have created an ATL 3.0 project including a simple object named MyObj with the attribute of 'appobject' on it's coclass. It has a property named MyString that holds string values. I have successfully built it and then tested it from vb. I have access to MyString property directly without instantiating MyObj. everythings is Ok. but I have problem with VC. From a Console application which has access to that type library (via import directive) MyString property cannot be accessed without qualification. With the statement: MyString = "Hello world!"; compiler generates following error: error C2065: 'MyString' : undeclared identifier what is the problem? do you think i should use a special syntax? if so, would you please help me to know how i can use it? thanks in advance Roozbeh

    A 1 Reply Last reply
    0
    • R Roozbeh69

      Hello everybody, I am a beginner in com programming, and i have a question: I have created an ATL 3.0 project including a simple object named MyObj with the attribute of 'appobject' on it's coclass. It has a property named MyString that holds string values. I have successfully built it and then tested it from vb. I have access to MyString property directly without instantiating MyObj. everythings is Ok. but I have problem with VC. From a Console application which has access to that type library (via import directive) MyString property cannot be accessed without qualification. With the statement: MyString = "Hello world!"; compiler generates following error: error C2065: 'MyString' : undeclared identifier what is the problem? do you think i should use a special syntax? if so, would you please help me to know how i can use it? thanks in advance Roozbeh

      A Offline
      A Offline
      Andrew Quinn AUS
      wrote on last edited by
      #2

      Hi, Not to sure why you are getting a problem. Here is an example of how to use it in VC++ (see if it differs to yours) First, the #import

      #import "D:\My Projects\C++\MyObj\MyObj.tlb"
      using namespace MyObjLib;

      Add the namespace to avoid any conflicts with other COM objects you may use that will have the same name. Now when using it:

      MyObjLib::IMyObjPtr pMyObj = NULL;
      try
      {
      	if (SUCCEEDED(pMyObj.CreateInstance(\_\_uuidof(MyObjLib::MyObj))) && pMyObj != NULL)
      	{
      		pMyObj->MyString = \_T("Hello");
      	}
      }
      catch(\_com\_error &e)
      {
      }
      

      This ultimately will use the wrapper method PutMyString( _bstr_t pVal ) that is defined in the two new files generated by the #import statement. These should be in your Debug/Release directories and called MyObj.tlh and MyObj.tli. Ones the header file, the other the implementation file. Have a look through them to see how your COM object has been wrapped. Hope this has helped, Andy

      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