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. Object Initialization Problem

Object Initialization Problem

Scheduled Pinned Locked Moved COM
helpquestion
5 Posts 2 Posters 2 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.
  • P Offline
    P Offline
    pjdriverdude
    wrote on last edited by
    #1

    I am having trouble with some objects. I'm getting access violations when trying to use some of the methods in the object, which I think is due to not initializing the object when I create it..but there's the problem, I can't use the new operator to create it because it complains about virtual functions. Here's the different ways I've tried to initialize it 1:

    IDgnWords words = new IDgnWords() ;

    Errors (some of them anyway): error C2259: 'IDgnWords' : cannot instantiate abstract class due to following members: warning C4259: 'unsigned long __stdcall IUnknown::AddRef(void)' : pure virtual function was not defined 2:

    IDgnWords* words ;
    words->Dump( CComBSTR("C:\\words.txt") ) ;

    Error: Access Violation when reaching the Dump function 3:

    CComPtr<IDgnWords> words ;
    words->Dump( CComBSTR("C:\\words.txt") ) ;

    Error: Run Time error. No message box pops up, but I can't step any further in the code while debugging. The class has no initialize functions so and I think this is where I'm having trouble. Is there something I should be doing to initialize the objects?

    S 1 Reply Last reply
    0
    • P pjdriverdude

      I am having trouble with some objects. I'm getting access violations when trying to use some of the methods in the object, which I think is due to not initializing the object when I create it..but there's the problem, I can't use the new operator to create it because it complains about virtual functions. Here's the different ways I've tried to initialize it 1:

      IDgnWords words = new IDgnWords() ;

      Errors (some of them anyway): error C2259: 'IDgnWords' : cannot instantiate abstract class due to following members: warning C4259: 'unsigned long __stdcall IUnknown::AddRef(void)' : pure virtual function was not defined 2:

      IDgnWords* words ;
      words->Dump( CComBSTR("C:\\words.txt") ) ;

      Error: Access Violation when reaching the Dump function 3:

      CComPtr<IDgnWords> words ;
      words->Dump( CComBSTR("C:\\words.txt") ) ;

      Error: Run Time error. No message box pops up, but I can't step any further in the code while debugging. The class has no initialize functions so and I think this is where I'm having trouble. Is there something I should be doing to initialize the objects?

      S Offline
      S Offline
      Sauro Viti
      wrote on last edited by
      #2

      The most significant information is done by your first attempt:

      1. error C2259: cannot instantiate abstract class due to following members: unsigned long __stdcall IUnknown::AddRef(void) As the compiler said, you cannot instantiate this class in any way, because it misses something; if you write the code of that class the solution is obvious: implement unsigned long __stdcall IDgnWords::AddRef(void) and this will fix you problem
      2. by writing IDgnWords* words; you have allocated only a pointer to that class, but you should initialize it with new IDgnWords() before use it. If you don't do it, the pointer hold a random address and trying to use it generates a memory protection fault
        CComPtr words; declares a smart-pointer to the IDgnWords class, then all that I said about IDgnWords* words; is still valid, and this is the reason of your crash. CComPtr simply wraps a IDgnWords* and calls the Release() method for you when the variable goes out of scope
      P 2 Replies Last reply
      0
      • S Sauro Viti

        The most significant information is done by your first attempt:

        1. error C2259: cannot instantiate abstract class due to following members: unsigned long __stdcall IUnknown::AddRef(void) As the compiler said, you cannot instantiate this class in any way, because it misses something; if you write the code of that class the solution is obvious: implement unsigned long __stdcall IDgnWords::AddRef(void) and this will fix you problem
        2. by writing IDgnWords* words; you have allocated only a pointer to that class, but you should initialize it with new IDgnWords() before use it. If you don't do it, the pointer hold a random address and trying to use it generates a memory protection fault
          CComPtr words; declares a smart-pointer to the IDgnWords class, then all that I said about IDgnWords* words; is still valid, and this is the reason of your crash. CComPtr simply wraps a IDgnWords* and calls the Release() method for you when the variable goes out of scope
        P Offline
        P Offline
        pjdriverdude
        wrote on last edited by
        #3

        As for attempt 1, I didn't write the code for the class (it's from Nuance Dragon Naturally Speaking SDK). For attempt 2, I get the same errors when doing: IDgnWords* words = new IDgnWords() ; (ie. cannot instantiate abstract class)

        1 Reply Last reply
        0
        • S Sauro Viti

          The most significant information is done by your first attempt:

          1. error C2259: cannot instantiate abstract class due to following members: unsigned long __stdcall IUnknown::AddRef(void) As the compiler said, you cannot instantiate this class in any way, because it misses something; if you write the code of that class the solution is obvious: implement unsigned long __stdcall IDgnWords::AddRef(void) and this will fix you problem
          2. by writing IDgnWords* words; you have allocated only a pointer to that class, but you should initialize it with new IDgnWords() before use it. If you don't do it, the pointer hold a random address and trying to use it generates a memory protection fault
            CComPtr words; declares a smart-pointer to the IDgnWords class, then all that I said about IDgnWords* words; is still valid, and this is the reason of your crash. CComPtr simply wraps a IDgnWords* and calls the Release() method for you when the variable goes out of scope
          P Offline
          P Offline
          pjdriverdude
          wrote on last edited by
          #4

          Now one thing that isn't making sense is I used a different class from this SDK and I was able to call CoCreateInstance( CLSID_DgnVocTools, NULL, CLSCTX_ALL, IID_IDgnVocTools, (LPVOID*)&pIDgnVocTools ) ; I would think that I would need to create and instance of the IDgnWords object, but there's no CLSID for it. If I don't create and instance of that VocTools object I used in the previous paragraph, it craps out on me just like the IDgnWords object is doing now. You think this could be the problem? It seems odd to me that creating a "new" object doesn't seem to work for this.

          S 1 Reply Last reply
          0
          • P pjdriverdude

            Now one thing that isn't making sense is I used a different class from this SDK and I was able to call CoCreateInstance( CLSID_DgnVocTools, NULL, CLSCTX_ALL, IID_IDgnVocTools, (LPVOID*)&pIDgnVocTools ) ; I would think that I would need to create and instance of the IDgnWords object, but there's no CLSID for it. If I don't create and instance of that VocTools object I used in the previous paragraph, it craps out on me just like the IDgnWords object is doing now. You think this could be the problem? It seems odd to me that creating a "new" object doesn't seem to work for this.

            S Offline
            S Offline
            Sauro Viti
            wrote on last edited by
            #5

            I thought that IDgnWords was a class that you wrote because COM classes should be created trough their class factory using the CoCreateInstance() function, or queried to another class that you have already instantiated using the QueryInterface() method. If there isn't a CLSID_ trough that you can instantiate the IDgnWords, probably you should first instantiate another class and then query it for the one you need... I tried searching the internet for documentation about IDgnWords, but I didn't find anything. Dragon Naturally Speaking is a payed product: have you got any documentation from Nuance? Have they give you any technical contact to ask for? I'm sorry, but I don't know what else to tell you :(

            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