I’m developing a credential provider and credential. So I have this class SampleProvider and SampleCredential. It works well when I specifically declare that SampleProvider has one, or two, or a constant number of SampleCredential, by declaring:
SampleCredential * _pCredential[2]
But now, I want it to be dynamically allocated. So I will have this:
SampleCredential * *_pCredential
And then inside the method SetUsageScenario(), the code will read the number of credentials from a txt file, and allocate it:
(*_pCredential) = new SampleCredential[numberCount];
But it is not working. I keep getting error on that line. It says
Access violation writing location 0x00000000 ;
Do you know what happens here and what to do?
_pCredential has probably not been initialized yet and is still NULL. Attempting to dereference the null pointer via “(*_pCredential)” would then result in your access violation.
Maybe you meant to do this?
That will allocate an array of pointers to SampleCredential objects. You can then allocate each SampleCredential object like this:
Remember to free the memory when you’re done: