Hi,
I have a managed package that deals with project output groups. Output
groups are accessed through IVsProjectCfg2.get_OutputGroups() method using
following code:
private IVsOutputGroup[] GetOutputGroups( IVsProjectCfg2 config )
{
uint[] elementCount = new uint[1];
IVsOutputGroup[] groups;
NativeMethods.ThrowOnFailure( config.get_OutputGroups( 0, null,
elementCount ) ); // Getting total number of output groups
groups = new IVsOutputGroup[elementCount[0]]; // Allocating target array
NativeMethods.ThrowOnFailure( config.get_OutputGroups( elementCount[0],
groups, null ) ); // Filling out array
return groups;
}
Everything is OK with C#, VB and even Setup projects, but as soon as I pass
configuration object from C++ project I've got an NullReferenceException at
the second call to get_OutputGroups. First call reports that this
configuration has 5 output groups, second call (to fill array) fails. I just
can't understand where the problem is. Another strange thing is that if (in
debugger) I'll change elementCount[0] from 5 to 1 just before second call
(when array is allocated) than reference to one of the groups is placed to
groups array. I've experimented with other values (from 2 to 5 :-) but in
all other cases error is reported by the call.
Can anybody point me to workaround or provide any hint?
Regards,
Gregory.
Gregory Nickonov - 03 Sep 2004 19:47 GMT
Never mind, I've just solved the problem :-) For those who is interested see
description below.
Quote from VSIP documentation on get_OutputGroups() method:
celt
[in] Requested number of output groups to be returned.
prgpcfg
[in, out, size_is(celt)] Pointer to an array of IVsOutputGroup interface
pointers.
pcActual
[out, optional] Pointer to the actual number of output groups returned.
If I got it right, than "pcActual" parameter is optional and can be set to
null, as I did. But that's not the case for C++ projects. Changing the
second call to be like:
NativeMethods.ThrowOnFailure( config.get_OutputGroups( elementCount[0],
groups, elementCount ) );
solved the problem.
Regards,
Gregory.
"
> Hi,
>
[quoted text clipped - 11 lines]
> groups = new IVsOutputGroup[elementCount[0]]; // Allocating target array
> NativeMethods.ThrowOnFailure( config.get_OutputGroups(
elementCount[0],
> groups, null ) ); // Filling out array
>
[quoted text clipped - 15 lines]
> Regards,
> Gregory.