static size_t _callback_shim(char* buffer, size_t size, size_t nmemb, _sg_curl* pMe, SG_curl__callback* pFn, void* pState) { SG_context* pCtx = pMe->pCtx; // so SG_ERR_CHECK works SG_uint32 len_handled = 0; SG_ERR_CHECK( pFn(pCtx, (SG_curl*)pMe, buffer, (SG_uint32)(size*nmemb), pState, &len_handled) ); return len_handled; fail: return CURL_READFUNC_ABORT; }
bool _DwmIsCompositionEnabled() { HMODULE library = LoadLibrary(L"dwmapi.dll"); bool result = false; if (library) { BOOL enabled = false; HRESULT (WINAPI *pFn)(BOOL *enabled) = (HRESULT (WINAPI *)(BOOL *enabled))(GetProcAddress(library, "DwmIsCompositionEnabled")); result = SUCCEEDED(pFn(&enabled)) && enabled; FreeLibrary(library); } return result; }
// This function sets the opacity and transparency color key of a layered window. // // Parameters: // [IN] hWnd // Handle to the layered window. // [IN] crKey // A COLORREF value that specifies the transparency color key to be used when // composing the layered window. All pixels painted by the window in this color will be transparent. // To generate a COLORREF, use the RGB() macro. // [IN] bAlpha // Alpha value used to describe the opacity of the layered window. // When bAlpha is 0, the window is completely transparent. // When bAlpha is 255, the window is opaque. // [IN] dwFlags // Specifies an action to take. This parameter can be one or more of the following values: // LWA_COLORKEY Use crKey as the transparency color. // LWA_ALPHA Use bAlpha to determine the opacity of the layered window. // // Return value: // TRUE // Function executed successfully. // FALSE // Function failed. To get extended error information, call ::GetLastError(). // BOOL CLayeredWindowHelperST::SetLayeredWindowAttributes(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags) { BOOL bRetValue = TRUE; if (m_hDll) { lpfnSetLayeredWindowAttributes pFn = NULL; pFn = (lpfnSetLayeredWindowAttributes)GetProcAddress(m_hDll, "SetLayeredWindowAttributes"); if (pFn) { bRetValue = pFn(hWnd, crKey, bAlpha, dwFlags); } // if else bRetValue = FALSE; } // if return bRetValue; } // End of SetLayeredWindowAttributes
void CMeshMathSurface::BuildParametricSurface(unsigned long nVx, unsigned long nVy, float x0, float y0, float du, float dv, VECTOR4D(*pFn)(float u, float v)) { float x, y = y0; m_Indices.clear(); m_Vertices.clear(); m_nVx = nVx; m_nVy = nVy; m_Vertices.resize(m_nVx * m_nVy); for (unsigned long j = 0; j < m_nVy; j++) { x = x0; for (unsigned long i = 0; i < m_nVx; i++) { VECTOR4D P = pFn(x, y); m_Vertices[j * m_nVx + i].Position = P; x += du; } y += dv; } Tesselate(); }
void CMeshMathSurface::BuildAnalyticSurface(unsigned long nVx, unsigned long nVy, float x0, float y0, float dx, float dy, float(*pFn)(float x, float y)) { float x, y = y0; m_Indices.clear(); m_Vertices.clear(); m_nVx = nVx; m_nVy = nVy; m_Vertices.resize(m_nVx * m_nVy); for (unsigned long j = 0; j < m_nVy; j++) { x = x0; for (unsigned long i = 0; i < m_nVx; i++) { VECTOR4D P = { x, y, pFn(x, y), 1 }; m_Vertices[j * m_nVx + i].Position = P; x += dx; } y += dy; } Tesselate(); }
//**************************************************************************** // // handle 'len' bytes of 'pBuf' and advance the gdb state machine // accordingly. Handle packets in the format of ....$<payload>#nn // // When a complete packet has been received, call pFn passing the GDB // context structure and a boolean flag indicating whether or not the // checksum was valid. // //**************************************************************************** void gdb_statemachine(GDBCTX *pGdbCtx, unsigned char *pBuf, unsigned int len, void(*pFn)(GDBCTX*, int)) { while (len--) { switch(pGdbCtx->gdb_state) { case GDB_IDLE: TRACE(0, "GDB_IDLE: '%c'\n", *pBuf); if (*pBuf == '$') { pGdbCtx->gdb_state = GDB_PAYLOAD; } if (*pBuf == '+') { pGdbCtx->iAckCount++; } if (*pBuf == '-') { pGdbCtx->iNakCount++; } pGdbCtx->pResp[pGdbCtx->iRd++] = *pBuf; if (*pBuf == 0x03) { /* GDB Ctrl-C */ if (pFn) { pFn(pGdbCtx, 1); pGdbCtx->iRd = 0; } } pBuf++; break; case GDB_PAYLOAD: TRACE(0, "GDB_PAYLOAD: '%c' 0x%02x\n", isprint(*pBuf) ? *pBuf : '.', *pBuf); pGdbCtx->pResp[pGdbCtx->iRd++] = *pBuf; if (*pBuf == '#') { pGdbCtx->gdb_state = GDB_CSUM1; } pBuf++; break; case GDB_CSUM1: TRACE(0, "GDB_CSUM1: '%c'\n", *pBuf); pGdbCtx->csum = hexchartoi(*pBuf) << 4; pGdbCtx->gdb_state = GDB_CSUM2; pGdbCtx->pResp[pGdbCtx->iRd++] = *pBuf; pBuf++; break; case GDB_CSUM2: TRACE(0, "GDB_CSUM2: '%c'\n", *pBuf); pGdbCtx->csum |= hexchartoi(*pBuf); pGdbCtx->pResp[pGdbCtx->iRd++] = *pBuf; if (pFn) { if (gdb_validate(pGdbCtx->pResp, pGdbCtx->csum) == 0) { pFn(pGdbCtx, 1); } else { pFn(pGdbCtx, 0); } } pGdbCtx->iRd = 0; pGdbCtx->gdb_state = GDB_IDLE; pBuf++; break; } } }