Evan Carslake
Evan Carslake

Reputation: 2349

C++ Win32 IStream to string problems

NOTE: I have googled, searched and tried out every single thing I found.

The real issue is that I am trying to use IStream with things like get, getline, read, put

The error, IStream has no member named 'read'

The code:

// For version info and etc
HRSRC srcTest =   FindResource(NULL, MAKEINTRESOURCE(2), RT_VERSION);
HGLOBAL hGlobal = LoadResource(NULL, srcTest);

// Gets the size of the resource, and locks it to get a pointer
int size = SizeofResource(NULL, srcTest); 
LPVOID resPtr = LockResource(hGlobal); 

hGlobal = GlobalAlloc(GMEM_FIXED, size); 

// Copies the raw data into allocated space
 memcpy(hGlobal, resPtr, size);

// Cleans
FreeResource(hGlobal);

// Creates a stream 
IStream* in = NULL;
CreateStreamOnHGlobal(hGlobal, true, &in);


// One example test
std::string ret;
char buffer[4096];

while (in->read(buffer, sizeof(buffer)))

ret.append(buffer, sizeof(buffer));
ret.append(buffer, in.gcount());

The resource is coming directly from VERSION_INFO in the resource file. I have tested and that is absolutely not the problem.

Thanks.

Upvotes: 0

Views: 1439

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37122

C++ is case-sensitive; the method is named Read() (it's actually defined in ISequentialStream which IStream inherits from).

Note that it takes three parameters, not the two you are trying to pass it.

HRESULT Read( [out] void *pv, [in] ULONG cb, [out] ULONG *pcbRead );

Parameters

pv [out] A pointer to the buffer which the stream data is read into.

cb [in] The number of bytes of data to read from the stream object.

pcbRead [out] A pointer to a ULONG variable that receives the actual number of bytes read from the stream object.

Upvotes: 3

Related Questions