Re: NullReferenceException after a Marshal.StructureToPtr

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Seasanctuary (seasanctuary_at_yahoo.com)
Date: 05/18/04


Date: 18 May 2004 10:38:58 -0700

I've noticed that if I set ecList.nUser = 0 instead of = 1 then
AddUsersToEncryptedFile completes without the NullReferenceException.

I'm inclined to think that I'm missing an array initialization.
pUsers is supposed to be a pointer to the first member of the array of
certificates. I'm just giving it a pointer to the one certificate
I've set up. Perhaps the marshaller needs to be told it's dealing
with an array so it remembers to initialize one, even if it will only
hold the one value and even if the number of array members is listed
in nUser.

Am I on the right track here?

Thanks,
Seasanctuary

////Excerpt from what I posted last time for quick reference...

//Put the one encryption certificate in a list (of one member).
Win32.ENCRYPTION_CERTIFICATE_LIST ecList;
ecList.nUser = 1;
ecList.pUsers = encryptionCertificatePointer;

//Finally, the encryption certificate list can be applied to a certain
file.
string targetFile = @"C:\test.txt";
Win32.AddUsersToEncryptedFile(targetFile, ref ecList);



Relevant Pages

  • Re: Address of an array = address of its 1st element: undecidable question ?
    ... | the address of the first member of the array. ... There is wording to that effect in 6.7.2.1p13 with respect to structures and their first member, but I couldn't find comparable wording about arrays and their first element; by analogy with structures, I'd expect such wording to be in section 6.7.5.2; I couldn't find it there, or anywhere else that I looked. ... I recall the Standard says: ... silent on the question of where it is that a pointer points, that is the result from the conversion of a pointer of a different type. ...
    (comp.lang.c)
  • Re: passing an array to a function?
    ... >> a pointer to the first member of the array. ... >> would decay into a pointer to a pointer. ...
    (comp.lang.c)
  • Re: passing an array to a function?
    ... You aren't returning a pointer to an array. ... > a pointer to the first member of the array. ... can in certain contexts decay ...
    (comp.lang.c)
  • Re: Passing arrays into unmanaged code
    ... you can pin the first member of the array something like that: ... the entire array is now pinned and you have a pointer to the start of ...
    (microsoft.public.dotnet.languages.vc)
  • Re: passing an array to a function?
    ... > Nitpick: You aren't returning a pointer to an array. ... > a pointer to the first member of the array. ...
    (comp.lang.c)