Skip to content

Instantly share code, notes, and snippets.

@caiorss
caiorss / ws-scripting.cpp
Created January 2, 2019 07:44
Add scripting capability to your C++ project using Windows Script Host
#include <windows.h>
#include <objbase.h>
#include <activscp.h>
#include <atomic>
#include <cassert>
#include <cstdio>
class ScriptSite : public IActiveScriptSite
{
public:
@caiorss
caiorss / Mixin.cc
Created October 17, 2018 17:25 — forked from langthom/Mixin.cc
Exemplary demonstration of how Mixins could be implemented in C++.
// Simple mixins in C++. Thomas Lang, 2018.
#include <iostream>
#include <list>
namespace {
// add const reference to type.
template<typename T>
struct add_cref : std::add_lvalue_reference<std::add_const<T> > {};
@caiorss
caiorss / mfencode.cpp
Created October 17, 2018 17:22 — forked from lxfly2000/mfencode.cpp
用MF转换音频文件到MP3
//用Windows Media Foundation将任何Windows支持的音频文件转换成MP3格式文件,仅限Windows 8(NT6.2)及以上操作系统。
#include<new>
#include<iostream>
#include<string>
#include<locale.h>
#include<Windows.h>
#include<mfapi.h>
#include<mfidl.h>
#include<Shlwapi.h>
#pragma comment(lib,"mfplat.lib")
@caiorss
caiorss / product.cpp
Created October 17, 2018 17:20 — forked from Alexhuszagh/product.cpp
Cartesian Product Implementation in C++
// :copyright: (c) 2017 Alex Huszagh.
// :license: MIT.
/**
* Cartesian product algorithm.
*
* Lazily calculates the cartesian product from a container of containers,
* of either linear (array, vector, set, unordered_set) or associative
* (map, unordered_map, multimap, unordered_multimap) containers.
*
* The code can be used as follows:
@caiorss
caiorss / DllMain.cpp
Created August 21, 2018 13:46 — forked from bg1bgst333/DllMain.cpp
IUnknown#IUnknown
#include <cstdio> // 標準入出力
#include <tchar.h> // TCHAR対応
static long g_lLock = 0; // ロック
#include "Unknown.h" // Unknownの宣言
static CUnknown g_Unknown; // Unknownオブジェクト
HMODULE g_hModule = NULL;
extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){
g_hModule = hinstDLL;
return TRUE;
// C/C++ Common
#include <cstdio>
#include <map>
// Windows
#include <windows.h>
class __declspec( uuid( "3D48D1EB-1EA5-4D4B-8411-4C0B8DF72CD7" ) ) ITestClass : public IUnknown
{
protected:
@caiorss
caiorss / lock.cpp
Created August 20, 2018 15:26 — forked from taeguk/lock.cpp
Lock/Unlock Session by the "computer using rule" in Windows.
/*
Lock/Unlock Session by the "computer using rule".
Support versions >= Windows 7
https://gist.github.com/taeguk/13b607f42020981f6cf9
*/
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include <Wtsapi32.h>
@caiorss
caiorss / excel_dispatch_client.cpp
Created August 20, 2018 15:25 — forked from derrickturk/excel_dispatch_client.cpp
An IDispatch client that launches Excel for 25 seconds.
// build with g++ -std=c++14 -O2 -Wall -Wextra -pedantic -static -o excel_dispatch_client excel_dispatch_client.cpp -lole32 -luuid
#include <cstdlib>
#include <iostream>
#include <exception>
#include <memory>
#include <string>
#include <sstream>
#include <vector>
#include <unordered_map>
@caiorss
caiorss / AboutDlg.cpp
Created August 20, 2018 15:24 — forked from yak1ex/AboutDlg.cpp
MX FLOW
#include <windows.h>
#include <Strsafe.h>
#include <vector>
#include <boost/align/aligned_allocator.hpp>
typedef boost::alignment::aligned_allocator<void, 4> aligned_allocator;
class buffer
{
public:
@caiorss
caiorss / ccom.cpp
Created August 20, 2018 15:15 — forked from kasajian/ccom.cpp
Creating a COM Object in plain C++
#include <windows.h>
#include "ccom.h"
// In order to use from VBScript, you need to place the progID in the registry so
// that it can be used to obtain the CLSID of this class.
// VB script
/*
DIM X
DIM Y
SET X = CREATEOBJECT( "BrlsMath.Math" )