Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting raw data from COM EXE-server.

Status
Not open for further replies.

ZakiMaksyutov

Programmer
Feb 28, 2001
87
0
0
RU
Hi!

I would like to have function in my COM EXE-server:
HRESULT GetData(byte** ppb, long& plBytes); or something like this.
This function should allocate memory, store data in it and return. But I don't know how to do this. I can't simply allocate :(
May be there is another approach (may be SafeArray, I don't know)?

Thanks for any help.
 
Ok. Problem was solved.

STDMETHODIMP CExeTestServer::GetData(VARIANT* pvar)
{
// Data:
char* lpszData = new char[64];
strcpy(lpszData, "Hello, world!");

// Creating and filling SafeArray.
long lBytes = (strlen(lpszData)+1)*sizeof(char);
SAFEARRAYBOUND aDim[1];
aDim[0].lLbound = 1;
aDim[0].cElements = lBytes;
SAFEARRAY* psa = SafeArrayCreate(VT_UI1, 1, aDim);
if (!psa)
return E_OUTOFMEMORY;
void* pv;
HRESULT hr = SafeArrayAccessData(psa, &pv);
if (FAILED(hr))
{
delete[] lpszData;
SafeArrayDestroy(psa);
return hr;
}
memcpy(pv, lpszData, lBytes);
SafeArrayUnaccessData(psa);

// Attach SafeArray to VARIANT.
pvar->vt = VT_ARRAY|VT_UI1;
pvar->parray = psa;

delete[] lpszData;

return S_OK;
}




 
I can't understand, do you want to use clipboard there? John Fill
1c.bmp


ivfmd@mail.md
 
no
I wanted to have method GetData in interface IExeTestServer of my COM EXE-Server which should return some data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top