Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

converting const unsigned* to SAFEARRAY**

4 views
Skip to first unread message

Pradeep

unread,
Mar 27, 2009, 11:44:39 AM3/27/09
to
Hi all ,
I am struggling to get the below code work which uses parameter
SAFEARRAY**.
I have written a small test program to send the test octets as
follows.

STDMETHODIMPL
TestOctetImp :: Send()
{

const unsigned char TestPkt[] = {
0x00, 0x01, 0xE0, 0x40, 0x00, 0x01, 0xF0, 0x40,
0x00, 0x02, 0x01, 0x40, 0x45, 0x00, 0x00, 0x40,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x82, 0xAA,
0xC0, 0x12, 0x01, 0x01, 0x01, 0x00, 0x36, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x10, 0x12, 0x02, 0x01, 0x3C, 0xCC, 0x9A,
0x57, 0xF2, 0x31, 0x2A, 0x9F, 0x47, 0xA2, 0xE0,
0x00, 0x00, 0x00, 0x00};

const unsigned char * frameBytes[] = {
TestPkt }


// Create a safe array to hold octets
// Copy the contents of the octets in to the safe array


const unsigned long NumTestPackets = sizeof(TestPkt)/sizeof
(TestPkt[0]);
SAFEARRAYBOUND sabound[1];
sabound[0].lLbound = 0;
sabound[0].cElements = NumTestPackets;
SAFEARRAY **psaOctets =0;-------------CRASH HERE
*psaOctets = SafeArrayCreate(VT_UI1, 2, sabound);
SIL_ASSERT(*psaOctets != 0);
unsigned char *psaData = 0;
hr = SafeArrayAccessData(*psaOctets, (void **) &psaData);
SIL_ASSERT(hr == S_OK);
//memcpy(psaData,frameBytes,NumMplsTestPackets+1);
long lCount = 0L;
SafeArrayPutElement(*psaOctets,&lCount, static_cast<void*>
(&frameBytes) );


long handle = 1;
SendOctets(handle,psaOctets);

}

--------
IN IDL:(Generated .h file from IDL)
-------
SendOctets(long Handle, SAFEARRAY**octets);


Could anyone please help me in this regard?

Regards
Sobhan

0 new messages