cef/tests/cefclient/resource_util.cpp
Marshall Greenblatt d7f7f45147 Move to GYP-based project file generation (issue #48).
- Add cef_create_projects.bat to generate the CEF project files.
- Change include paths to be relative to the root CEF directory.
- Add patch_build configuration and build.patch to modify the Chromium build system for required CEF dependencies.
- Remove old .vcproj and .vsprops files.
- Eliminate use of precompiled headers.
- Commit generated project files (these will go away in the near future).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@50 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
2009-10-02 17:59:38 +00:00

91 lines
1.8 KiB
C++

// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "resource_util.h"
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes)
{
extern HINSTANCE hInst;
HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(binaryId),
MAKEINTRESOURCE(256));
if(hRes)
{
HGLOBAL hGlob = LoadResource(hInst, hRes);
if(hGlob)
{
dwSize = SizeofResource(hInst, hRes);
pBytes = (LPBYTE)LockResource(hGlob);
if(dwSize > 0 && pBytes)
return true;
}
}
return false;
}
// ClientReadHandler implementation
ClientReadHandler::ClientReadHandler(LPBYTE pBytes, DWORD dwSize)
: bytes_(pBytes), size_(dwSize), offset_(0) {}
size_t ClientReadHandler::Read(void* ptr, size_t size, size_t n)
{
Lock();
size_t s = (size_ - offset_) / size;
size_t ret = min(n, s);
memcpy(ptr, bytes_ + offset_, ret * size);
offset_ += ret * size;
Unlock();
return ret;
}
int ClientReadHandler::Seek(long offset, int whence)
{
int rv = -1L;
Lock();
switch(whence) {
case SEEK_CUR:
if(offset_ + offset > size_) {
break;
}
offset_ += offset;
rv = offset_;
break;
case SEEK_END:
if(offset > (int)size_) {
break;
}
offset_ = size_ - offset;
rv = offset_;
case SEEK_SET:
if(offset > (int)size_) {
break;
}
offset_ = offset;
rv = offset_;
break;
}
Unlock();
return rv;
}
long ClientReadHandler::Tell()
{
Lock();
long rv = offset_;
Unlock();
return rv;
}
int ClientReadHandler::Eof()
{
Lock();
int rv = (offset_ >= size_);
Unlock();
return rv;
}