Pergunta

Hai i want to convert the &var values into char array. how can i achieve this? i am using C++ Win32 API. Safe Array to Char

Open image in another tab,you will get clear View.

Thanks in advance.

Foi útil?

Solução

The easiest way is to use ATL::CComSafeArray. Assume you have a pointer to safe array in variable pSa,

CComSafeArray<BSTR> array;
array.Attach(pSa);

for(int i=0; i< array.GetCount(); ++i)
{
  std::wcout << (const wchar_t*) array[i] << std::endl;
}

If you want to use just win32,

SafeArrayLock(pSa);
LONG uBound = -1, lBound = 0;
SafeArrayUBound(pSa,1,uBound);
SafeArrayUBound(pSa,1,lBound);
int nCount = uBound - lBound + 1;
for(int i = 0; i<nCount; ++i)
{
 std::wcout << ((BSTR*)(pSa->pvData))[i] << std::endl;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top