Skip to content

Instantly share code, notes, and snippets.

View eahydra's full-sized avatar

Joseph eahydra

View GitHub Profile
@eahydra
eahydra / pe_checksum.c
Created September 19, 2012 05:03
pe file checksum
unsigned short ChkSum(unsigned int CheckSum, void *FileBase, int Length)
{
int *Data;
int sum;
if ( Length && FileBase != NULL)
{
Data = (int *)FileBase;
do
@eahydra
eahydra / open_registry.c
Created September 19, 2012 05:09
open registry by regedit.exe automation
BOOL TerminateProcessByPid(DWORD Pid)
{
BOOL Result = FALSE;
HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
if (ProcessHandle != NULL)
{
Result = TerminateProcess(ProcessHandle, 0);
CloseHandle(ProcessHandle);
}
@eahydra
eahydra / network_change.cpp
Created September 19, 2012 05:12
network change
class CNetworkListManagerEvent : public INetworkListManagerEvents
{
public:
CNetworkListManagerEvent() : m_ref(1)
{
}
~CNetworkListManagerEvent()
{
void WaitForNetworkChnages()
{
WSAQUERYSET querySet = {0};
querySet.dwSize = sizeof(WSAQUERYSET);
querySet.dwNameSpace = NS_NLA;
HANDLE LookupHandle = NULL;
WSALookupServiceBegin(&querySet, LUP_RETURN_ALL, &LookupHandle);
DWORD BytesReturned = 0;
@eahydra
eahydra / save_icon_to_file.cpp
Created September 20, 2012 04:43
save icon to file
bool SaveImageListToFile(HIMAGELIST hImageList, const TCHAR* FilePath)
{
if (hImageList != NULL)
{
::DeleteFile(FilePath);
IStorage *pStorage = NULL;
HRESULT hr = StgCreateStorageEx(FilePath,
STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE,
STGFMT_DOCFILE,
@eahydra
eahydra / task_thread_pool.cpp
Last active December 14, 2015 14:18
A task thread pool Demo. Just create some thread, and then poll task.
#include "task_thread_pool.hpp"
#include <assert.h>
#include <ustd/thread/guard.h>
namespace wx {
namespace utility {
task_thread_pool_t::task_thread_pool_t() : current_task_thread_(0) {}
task_thread_pool_t::~task_thread_pool_t()
#ifndef ASYNC_EXTEND_HPP_
#define ASYNC_EXTEND_HPP_
#include <future>
namespace base {
namespace detail {
template<typename future_t, typename handler_t>
struct async_helper {
static auto async_impl(std::launch::launch policy, future_t f, handler_t&& handler, std::true_type)->std::future<decltype(handler(f))>
#ifndef ERROR_CODE_HPP_
#define ERROR_CODE_HPP_
// define self error code
namespace base {
enum system_error_t {
kAccessDenied = ERROR_ACCESS_DENIED,
};
class system_category_t : public std::error_category {
#ifndef SCOPE_EXIT_HPP_
#define SCOPE_EXIT_HPP_
#include <functional>
namespace base {
template <typename handler_t>
class scope_exit {
private:
@eahydra
eahydra / task_thread_pool.cpp
Last active July 26, 2019 09:38
a task thread pool base on Windows IOCP. Support asynchronous task with closure and timer.
#include "task_thread_pool.hpp"
#include <set>
#include <vector>
#include <tuple>
#include <algorithm>
#include <Windows.h>
#include <assert.h>
#include <mutex>
namespace base {