Skip to content

Instantly share code, notes, and snippets.

@wyyqyl
wyyqyl / MsgThread.cpp
Created April 10, 2014 07:59
Integrate boost::thread with Windows MSG
#include <windows.h>
#include <boost/thread/thread.hpp>
LRESULT MsgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
LRESULT result = 0;
switch (message) {
case WM_TIMER:
std::cout << "WM_TIMER" << std::endl;
result = 1;
break;
@wyyqyl
wyyqyl / GetTcpTable2.cpp
Created April 9, 2014 03:38
Print network connection state
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <stdio.h>
// Need to link with Iphlpapi.lib and Ws2_32.lib
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
@wyyqyl
wyyqyl / FileVersion.cpp
Created April 8, 2014 09:45
Get file version with WIN32 API
// FileVersion.h: interface for the CFileVersion class.
// by Manuel Laflamme
//////////////////////////////////////////////////////////////////////
#ifndef __FILEVERSION_H_
#define __FILEVERSION_H_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
class CFileVersion {
// Construction
@wyyqyl
wyyqyl / util.cpp
Last active August 29, 2015 13:58
debug utility encapsulating OutputDebugStringA
#include <windows.h>
#include <stdio.h>
#define UID "[yy]"
#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x
#define LINE_STRING STRINGIZE(__LINE__)
#define DEBUG_PREFIX "["__FUNCTION__":"LINE_STRING"] "
@wyyqyl
wyyqyl / IUnknown.cpp
Created March 25, 2014 13:57
QueryInterface, AddRef, Release
#include <objbase.h>
#include <iostream>
interface IX : IUnknown {
virtual void Fx() = 0;
};
interface IY : IUnknown {
virtual void Fy() = 0;
};
@wyyqyl
wyyqyl / ipc.cpp
Created December 24, 2013 07:28
interprocess communication with boost::interprocess
#include <iostream>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/ipc/message_queue.hpp>
using namespace boost::interprocess;
const char kSharedMemory[] =
"asdv2_adblock_shared_object_{5095C5F0-D82D-4442-9A62-8769871F42D1}";
const char kMessageQueue[] =
"asdv2_adblock_shared_queue_{5095C5F0-D82D-4442-9A62-8769871F42D1}";
@wyyqyl
wyyqyl / v8Template.cpp
Created October 25, 2013 07:04
shows the difference between PrototypeTemplate and InstanceTemplate
#include <v8.h>
#include <vld.h>
#include <iostream>
void InvokeCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
std::cout << "InvokeCallback" << std::endl;
}
void InstanceAccessorCallback(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& args) {
@wyyqyl
wyyqyl / GetAppVersion
Created May 26, 2013 04:34
Disable file system redirection for system32
#include <Windows.h>
#pragma comment(lib, "Version.lib")
BOOL GetAppVersion( char *LibName, WORD *MajorVersion, WORD *MinorVersion, WORD *BuildNumber, WORD *RevisionNumber )
{
DWORD dwHandle, dwLen;
UINT BufLen;
LPTSTR lpData;
VS_FIXEDFILEINFO *pFileInfo;
@wyyqyl
wyyqyl / TlsCallback.cpp
Created May 18, 2013 06:33
A code snippet shows how to use Tls callback in VC++
#include <Windows.h>
#include <stdio.h>
VOID NTAPI MyCallback(PVOID handle, DWORD reason, PVOID resv);
#pragma data_seg(".CRT$XLB")
PIMAGE_TLS_CALLBACK tls_entry = MyCallback;
#pragma data_seg()
#pragma comment(linker, "/INCLUDE:__tls_used")
void Dump(void *ptr, int buflen) {
unsigned char *buf = (unsigned char*)ptr;
int i, j;
for (i=0; i<buflen; i+=16) {
printf("%06x: ", i);
for (j=0; j<16; j++)
if (i+j < buflen)
printf("%02x ", buf[i+j]);
else
printf(" ");