3

I have a byte array that contains for example

byte mac[6] = {0x00, 0x8a, 0x0C, 0x98, 0x11, 0x15}.

When inserting it to a database using this statement

m_pWiFiRecords->Fields->Item[varColumnIndex]->Value = _variant_t((char*)(pRecord->bss_id));

It saves it as an empty array because the first element = 0x00 and when casting it as a byte array it saves it as -1.

Could you help me in figuring out the problem?

1 Answer 1

8

Here is what you would do to get the binary data into the _variant_t. If the database is set up to handle the binary data, it should work for you.

Note that the _variant_t will take care of doing a deep destroy on the SAFEARRAY when it goes out of scope, so you don't have to worry about doing a SafeArrayDestroy.

_variant_t var;
var.vt = VT_ARRAY | VT_UI1;

SAFEARRAYBOUND rgsabound[1];
rgsabound[0].cElements = 6;
rgsabound[0].lLbound = 0;

var.parray = SafeArrayCreate(VT_UI1,1,rgsabound);

void * pArrayData = NULL;    
SafeArrayAccessData(var.parray,&pArrayData);
memcpy(pArrayData, mac, 6); 
SafeArrayUnaccessData(var.parray);

m_pWiFiRecords->Fields->Item[varColumnIndex]->Value = var;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.