Object Initialization Problem
-
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?
-
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?
The most significant information is done by your first attempt:
- 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: implementunsigned long __stdcall IDgnWords::AddRef(void)
and this will fix you problem - by writing
IDgnWords* words;
you have allocated only a pointer to that class, but you should initialize it withnew 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 theIDgnWords
class, then all that I said aboutIDgnWords* words;
is still valid, and this is the reason of your crash.CComPtr
simply wraps aIDgnWords*
and calls theRelease()
method for you when the variable goes out of scope
- error
-
The most significant information is done by your first attempt:
- 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: implementunsigned long __stdcall IDgnWords::AddRef(void)
and this will fix you problem - by writing
IDgnWords* words;
you have allocated only a pointer to that class, but you should initialize it withnew 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 theIDgnWords
class, then all that I said aboutIDgnWords* words;
is still valid, and this is the reason of your crash.CComPtr
simply wraps aIDgnWords*
and calls theRelease()
method for you when the variable goes out of scope
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)
- error
-
The most significant information is done by your first attempt:
- 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: implementunsigned long __stdcall IDgnWords::AddRef(void)
and this will fix you problem - by writing
IDgnWords* words;
you have allocated only a pointer to that class, but you should initialize it withnew 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 theIDgnWords
class, then all that I said aboutIDgnWords* words;
is still valid, and this is the reason of your crash.CComPtr
simply wraps aIDgnWords*
and calls theRelease()
method for you when the variable goes out of scope
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. - error
-
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.I thought that
IDgnWords
was a class that you wrote because COM classes should be created trough their class factory using theCoCreateInstance()
function, or queried to another class that you have already instantiated using theQueryInterface()
method. If there isn't aCLSID_
trough that you can instantiate theIDgnWords
, probably you should first instantiate another class and then query it for the one you need... I tried searching the internet for documentation aboutIDgnWords
, 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 :(