示例#1
0
文件: main.cpp 项目: leiqunni/v2iewx
// ---------------------------------------------------------------------------
//
HBITMAP __fastcall TForm1::SPI_LoadImage(String fileName) {
	/* 対応プラグインの検索 */
	for (int i = 0; i < hSPI->Count; i++) { // プラグイン関数の取得
		SPI_ISSUPPORTED spi_issupported = (SPI_ISSUPPORTED) GetProcAddress((HMODULE) hSPI->Items[i], SPIPROC_ISSUPPORTED);
		SPI_GETPICTURE spi_getpicture = (SPI_GETPICTURE) GetProcAddress((HMODULE) hSPI->Items[i], SPIPROC_GETPICTURE);

		if (spi_issupported == NULL || spi_getpicture == NULL) {
			continue;
		}

		// File内容をロードする
		HANDLE handle; // = NULL;

		if ((handle = CreateFile_Read(fileName.w_str())) == INVALID_HANDLE_VALUE) {
			return NULL;
		}

		DWORD filesize = GetFileSize(handle, NULL), readsize;
		LPSTR data = (LPSTR) Heap_Malloc(filesize);
		SetFilePointer(handle, 0, NULL, FILE_BEGIN);

		if (!ReadFile(handle, data, filesize, &readsize, NULL)) {
			CloseHandle(handle);
		}

		CloseHandle(handle);

		// ロードできる形式かどうかをチェックする
		if (spi_issupported(AnsiString(fileName).c_str(), (DWORD) data) == 0) {
			Heap_Free(data);
			continue;
		}

		// 画像を展開する
		HLOCAL info, bm;
		if (spi_getpicture(data, filesize, 1, &info, &bm, NULL, 0) != 0) {
			Heap_Free(data);
		}

		LPBITMAPINFO bmpinfo = (LPBITMAPINFO) LocalLock(info); // BITMAPINFO構造体
		LPBYTE bmbits = (LPBYTE) LocalLock(bm); // 画像データ

		// 取得した情報からBITMAPハンドルを生成する
		HDC dc = GetDC(0);
		HBITMAP bitmap = CreateDIBitmap(dc, &bmpinfo->bmiHeader, CBM_INIT, bmbits, bmpinfo, DIB_RGB_COLORS);
		ReleaseDC(0, dc);

		// Free etc...
		LocalUnlock(info);
		LocalFree(info);
		LocalUnlock(bm);
		LocalFree(bm);
		Heap_Free(data);

		return bitmap;
	}

	return NULL;
}
示例#2
0
void InventoryEntryData::Delete(void)
{
	if (extendDataList)
	{
		extendDataList->Delete();
		extendDataList = NULL;
	}
	Heap_Free(this);
}
示例#3
0
static const char *Heap_Alloc_test()
{
    Heap *heap = Heap_Construct(heapNone);
    void *mem = Heap_Alloc(heap, 10);
    Heap_Free(heap, mem);

    mu_assert(mem != NULL, "no mem");
    mu_assert_success();
    return NULL;
}
示例#4
0
/**
 * @brief TLSP based PAL free function
 *
 * @param pMem   Memory block to free
 *
 * @return SIRF_SUCCESS if successful, SIRF_FAILURE otherwise
 */  
tSIRF_RESULT SIRF_PAL_OS_MEM_Free(void *pMem)
{
   tSIRF_RESULT result = SIRF_PAL_OS_ERROR;

   if (SIRF_TRUE == s_mem_initialized)
   {
      (void)SIRF_PAL_OS_MUTEX_Enter(s_MemoryMutex);
      Heap_Free(s_MemoryHeap, pMem);
      (void)SIRF_PAL_OS_MUTEX_Exit(s_MemoryMutex);

      result = SIRF_SUCCESS;
   }
   
   return result;
}
/** 
 * Process all the messages on one of the GPRS queues
 * 
 * @param msg_queue Which message queue to process
 * @param handler   Which handler function to use
 * @param timeout   Pointer to amount of time to wait for the next message.  
 *                  This is set to SIRF_TIMEOUT_INFINITE if there are no 
 *                  messages left on the queue.
 * 
 * @return result of the handler or SIRF_SUCCESS if there are no messages
 * process.  
 */
static tSIRF_RESULT process_next_msg( 
   fifo_queue_t            * const msg_queue,
   tGPRS_MSG_HANDLER               handler,
   tSIRF_UINT32            * const timeout)
{
   gprs_msg_t *msg;
   fifo_link_t *link;
   tSIRF_RESULT result;

   UTIL_Assert(NULL != msg_queue);
   UTIL_Assert(NULL != handler);

   result = SIRF_PAL_OS_MUTEX_Enter(gprs_at_command.queue_mx);

   if(SIRF_SUCCESS != result)
   {
      return result;
   }
    
   /* Get the next message */
   link = fifo_queue_remove_head( msg_queue );

   result = SIRF_PAL_OS_MUTEX_Exit(gprs_at_command.queue_mx);
   if(SIRF_SUCCESS != result)
   {
      return result;
   }

   if (NULL != link)
   {
      msg = (gprs_msg_t*) link->data;
      result = handler(msg,
                       timeout);
      Heap_Free(gprs_at_command.msg_heap,link);
   }
   else
   {
      /* No messages to process, we need to wait until one arrives */
      *timeout = SIRF_TIMEOUT_INFINITE;
   }

   return result;
}
/** 
 * Send a message previously allocated
 * 
 * @param msg The message to send.  Must have been previously allocated by 
 *            MsgMalloc
 * 
 * @return SIRF_SUCCESS if the message or specific error code.
 */
tSIRF_RESULT SIRF_GPRS_AT_COMMAND_SERVER_MsgSend(
   gprs_msg_t           const * const msg)
{
   tSIRF_RESULT result;
   fifo_link_t * link;
   
   UTIL_Assert(NULL != msg);

   link = (fifo_link_t*)((tSIRF_UINT32)msg - sizeof(fifo_link_t));

   if ( ((tSIRF_UINT32)msg->handle >= SIRF_GPRS_AT_COMMAND_MAX_HANDLES )  ||
        (NULL == gprs_at_command.listener[(tSIRF_UINT32)msg->handle].msg_callback ))
   {
      Heap_Free(gprs_at_command.msg_heap,link);
      return SIRF_GPRS_AT_COMMAND_SERVER_INVALID_HANDLE;
   }

   /* Check to see if we need to send a wipdata message,
    * Only do this if this is a MAS message and there isn't a data connection
    * already open for this handle */
   if ((SIRF_LC_MAS == SIRF_GET_LC(msg->message_id)) &&
       /* MAS Message.  If we aren't in data mode send a message */
       ((GPRS_SERVER_STATE_TCP_IP_DATA != gprs_at_command.state) ||
        /* If we are in data mode, but opened via a differen handle, send wipdata */
       ((GPRS_SERVER_STATE_TCP_IP_DATA == gprs_at_command.state) &&
        (msg->handle != gprs_at_command.data_handle)))
      )
   {
      gprs_at_command.data_handle = msg->handle;
      result = gprs_send_tcpip_wipdata(gprs_at_command.listener[(tSIRF_UINT32)msg->handle].data_index);
      if (SIRF_SUCCESS != result)
      {
         Heap_Free(gprs_at_command.msg_heap,link);
         return result;
      }
   }

   result = SIRF_PAL_OS_MUTEX_Enter( gprs_at_command.queue_mx );
   if (SIRF_SUCCESS != result) 
   {
      Heap_Free(gprs_at_command.msg_heap,link);
      return result;
   }

   /* Add it to the appripriate message queue */
   if (SIRF_LC_MAS == SIRF_GET_LC(msg->message_id))
   {
      fifo_queue_add_tail(&gprs_at_command.listener[(tSIRF_UINT32)msg->handle].msg_queue_mas_input, link);
   }
   else
   {
      fifo_queue_add_tail(&gprs_at_command.msg_queue_gprs_input, link);
   }

   result = SIRF_PAL_OS_MUTEX_Exit( gprs_at_command.queue_mx );
   if (SIRF_SUCCESS != result)
   {
      return result;
   }
   
   /* Signal that a new message has arrived */
   result = SIRF_PAL_OS_SEMAPHORE_Release( gprs_at_command.semaphore );

   return result;

} /* SIRF_GPRS_AT_COMMAND_Send() */
示例#7
0
/// Frees to the current thread heap.
// void Thread_Free(void* memory)
void FastCall(Thread_Free__fast(void *memory))
{
    if (memory == NULL) return;
    Heap_Free(CurrentThread.Heap, memory);
}