dangermoose Posted July 14, 2004 Share Posted July 14, 2004 i have an array referenced by the pointer pCNI->rgRDN->rgRDNAttr->Value.pbData; the reference pCNI->cRDN; tells me the number of elements and pCNI->rgRDN->rgRDNAttr->Value.cbData; tells me the size of each element. this array is system owned, and i need to make a copy of it to use for myself. this is where i am stuck. i know i need to use memcpy, as in the example here; buffer = new BYTE[pCNS->rgRDN->rgRDNAttr->Value.cbData] ; memcpy( buffer pCNS->rgRDN->rgRDNAttr->Value.pbData, pCNS->rgRDN->rgRDNAttr->Value.cbData); but the difference here is the value pCNI->cRDN; which was 1 for the above example. any ideas on how i copy the array into my own array? cheers people, this one is driving me mad! :angry: Link to comment Share on other sites More sharing options...
0 Oogle Posted July 14, 2004 Share Posted July 14, 2004 Assuming what you said is accurate... BYTE* sysbuffer = pCNI->rgRDN->rgRDNAttr->Value.pbData; size_t cElems = pCNI->cRDN; size_t cbElemSize = pCNI->rgRDN->rgRDNAttr->Value.cbData; BYTE* newbuffer = malloc(nElems*cbElemSize); memcpy( newbuffer, sysbuffer, nElems*cbElemSize ); You can't use new because it assumes that the size of each element is sizeof(BYTE). It's unclear whether pCNI->rgRDN->rgRDNAttr->Value.cbData equals sizeof(BYTE). Link to comment Share on other sites More sharing options...
0 OfF3nSiV3 Posted July 15, 2004 Share Posted July 15, 2004 i don't know C++ but i know a little o C and this pCNS->rgRDN->rgRDNAttr->Value.pbData looks like a struct of a pointer..and hell, is this a struct of a struct of a struct?? Link to comment Share on other sites More sharing options...
0 after fallout Posted July 15, 2004 Share Posted July 15, 2004 edit:nevermind, read your post and Oogles a couple of times and what I was going to say was wrong Link to comment Share on other sites More sharing options...
0 dangermoose Posted July 15, 2004 Author Share Posted July 15, 2004 yes that is a struct, of a struct, of a struct, good ol microsoft and cryptography, i swear they make the crypt sdk as hard to use as possible, thats their idea of secure i suppose :D AFAIK pCNI->rgRDN->rgRDNAttr->Value.cbData does equal sizeof(BYTE). well thats my understanding of it. the link to the msdn article is below, if it helps http://msdn.microsoft.com/library/default....ty/cert_rdn.asp. the problem is not that example, i think that works, the problem i have is making my own array that matches theirs, with their values in it for the more complex array. i confuse myself, so i hope you follow Link to comment Share on other sites More sharing options...
0 Oogle Posted July 15, 2004 Share Posted July 15, 2004 It looks like you want to basically make a deep copy of the CERT_RDN_ATTR array in CERT_RDN. Is that right? If that's the case... // Allocate memory for the CERT_RDN_ATTR array DWORD dwAttribs = pCNI->cRDNAttr; PCERT_RDN_ATTR rgAttribs = new CERT_RDN_ATTR[dwAttribs]; // Go through each CERT_RDN_ATTR in pCNI for( DWORD n=0; n < dwAttribs; n++ ) { const CERT_RDN_ATTR& CurrentAttrib = pCNI->rgRDNAttr[n]; // TODO: Make a deep copy of CurrentAttrib. rgAttribs[n].pszObjID = ... allocate memory for string, etc... rgAttribs[n].dwValueType = CurrentAttrib.dwValueType; rgAttribs[n].Value = ... allocate memory for blob, etc ... } Link to comment Share on other sites More sharing options...
Question
dangermoose
i have an array referenced by the pointer
pCNI->rgRDN->rgRDNAttr->Value.pbData;
the reference
pCNI->cRDN;
tells me the number of elements and
pCNI->rgRDN->rgRDNAttr->Value.cbData;
tells me the size of each element.
this array is system owned, and i need to make a copy of it to use for myself.
this is where i am stuck. i know i need to use memcpy, as in the example here;
buffer = new BYTE[pCNS->rgRDN->rgRDNAttr->Value.cbData] ;
memcpy(
buffer
pCNS->rgRDN->rgRDNAttr->Value.pbData,
pCNS->rgRDN->rgRDNAttr->Value.cbData);
but the difference here is the value pCNI->cRDN; which was 1 for the above example.
any ideas on how i copy the array into my own array?
cheers people, this one is driving me mad! :angry:
Link to comment
Share on other sites
5 answers to this question
Recommended Posts