摘要: class A{public: // Interface. void foo() { cout foo(); m_b->bar(); m_c->baz(); }};int main(int argc, char *argv[]){ Facade f(new A, new B, new C); f.qux(); // TODO: Release memory. return 0;} 阅读全文
posted @ 2013-01-24 15:59 walfud 阅读(143) 评论(0) 推荐(0) 编辑
摘要: qingwenclass Component{public: virtual void foo() = 0;};class LeafA : public Component{public: // Interface. virtual void foo() override { cout m_components;public: // Interface. virtual void foo() override { for (auto i : m_components) { i->foo(); } } void add(Component *componen... 阅读全文
posted @ 2013-01-23 13:54 walfud 阅读(105) 评论(0) 推荐(0) 编辑
摘要: class Adaptee{public: // Interface. void operator()(int a, int b, int c) { cout <<a; }};class Target{public: // Interface. virtual void operator()(int a) = 0;};class Adapter : public Target{ // data. Adaptee m_adaptee;public: Adapter(Adaptee &adaptee) : m_adaptee(adaptee) {}publ... 阅读全文
posted @ 2013-01-22 13:47 walfud 阅读(81) 评论(0) 推荐(0) 编辑
摘要: // Singleton.hclass Singleton{private: Singleton() {} ~Singleton() {} Singleton(Singleton const &other); Singleton &operator=(Singleton const &other);public: static Singleton &Instance() { return ms_singleton; } static Singleton ms_singleton;};// Singleton.cpp// PUT IT in ".cpp& 阅读全文
posted @ 2013-01-22 11:39 walfud 阅读(77) 评论(0) 推荐(0) 编辑
摘要: class Prototype{public: virtual Prototype *Clone() = 0;};class PrototypeA : public Prototype{public: virtual Prototype *Clone() override { return new PrototypeA(*this); }};class PrototypeB : public Prototype{public: virtual Prototype *Clone() override { return new Pro... 阅读全文
posted @ 2013-01-22 09:41 walfud 阅读(119) 评论(0) 推荐(0) 编辑
摘要: static constunsigned *s_someNames[aConstexpr];storage _ cv-qualification _type+ operator _ declarator-id _ operator;declarationdeclarator;put 'const' specifier to right of declaration is goes from here:http://www.dansaks.com/articles/1999-02%20const%20T%20vs%20T%20const.pdfI thouht 'cons 阅读全文
posted @ 2013-01-20 11:33 walfud 阅读(347) 评论(0) 推荐(0) 编辑
摘要: class T{ int *m_p; void foo() const { *m_p = 1234; }}; 不谈 'm_p' 的初始化及资源释放问题. 在 const member function 中, 竟然能修改类的成员变量? 这并不奇怪, 因为 const 成员函数的实质是: 不改变类的成员变量的值. 由于 'm_p' 是一个指针, 所以 const 的保护作用只能做用于不修改这个指针的值, 而不能限制指针所指向的内存的值.reference: http://bbs.csdn.net/topics/40265282 阅读全文
posted @ 2013-01-20 10:32 walfud 阅读(183) 评论(0) 推荐(0) 编辑
摘要: /* * ProductA. */class ProductA {};class Product1_A : public ProductA {public: Product1_A() { cout CreateProductA(); ProductB *pB = f->CreateProductB(); // TODO: Release memory. return 0;} 适用于类成分相同, 但是属于不同的系统。例如:windows 和 linux 的窗口应用程序组件。 此模式就像笛卡尔积一样, 使用一个抽象的工厂, 交叉的创建了某一系列的所有组件. 阅读全文
posted @ 2013-01-17 10:47 walfud 阅读(113) 评论(0) 推荐(0) 编辑
摘要: class Product {};class ProductA : public Product{public: ProductA() { cout <<"ProductA" <<endl; }};class ProductB : public Product{public: ProductB() { cout <<"ProductB" <<endl; }};class Creator{public: virtual Product *anOperation() = 0; virtual Product * 阅读全文
posted @ 2013-01-17 10:45 walfud 阅读(173) 评论(0) 推荐(0) 编辑
摘要: class Builder{protected: // data. string m_res;public: // Interface. virtual void buildPartA() = 0; virtual void buildPartB() = 0; virtual void buildPartC() = 0; string getRes() { return m_res; }};class BuilderA : public Builder{public: virtual void buildPartA() override { m_... 阅读全文
posted @ 2013-01-17 10:40 walfud 阅读(133) 评论(0) 推荐(0) 编辑
摘要: // main.cc//#include #include using namespace std;static int s_id = 0;class Observer;class Subject{ // data. vector m_observers;public: virtual ~Subject();public: // Interface. void addObserver(Observer *observer); void updateObservers();};class Observer{ // data. Subject *m_... 阅读全文
posted @ 2013-01-14 15:22 walfud 阅读(126) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std;class Visitor;class Element{public: virtual void accept(Visitor &vistor) = 0;};class Visitor{public: virtual void VisitElementA() = 0; virtual void VisitElementB() = 0;};class VisitorA : public Visitor{public: virtual void VisitElementA() { cout m_e... 阅读全文
posted @ 2013-01-14 09:39 walfud 阅读(297) 评论(1) 推荐(0) 编辑
摘要: 总体来看, c++11 从 5 方面进行了改善:语言更加严谨:(nullptr, enumClass, initializerList, override)语法更加便利:(auto, R"()", lambda, non static const member variable initialization)更大灵活性:(userDefinedLiterals)更加强大的底层控制:(alignas, alignof)更强大的库:(regex, 异步, 线程)autoThe use ofautoto deduce the type of a variable from its 阅读全文
posted @ 2013-01-05 16:49 walfud 阅读(1327) 评论(0) 推荐(0) 编辑
摘要: #include <Aclapi.h>int main(){ // Create file with multiple flags. HANDLE file = CreateFile("d:\\", STANDARD_RIGHTS_WRITE | WRITE_DAC, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_... 阅读全文
posted @ 2012-11-13 16:43 walfud 阅读(547) 评论(0) 推荐(0) 编辑
摘要: We can NOT use ITaskbarlist3 until windows has finished creation of button on taskbar.So, we have to wait a message.1. Get the message value::RegisterWindowMessage("TaskbarButtonCreated");2. Allow receiving message from explorer.exe and Wait windows to notify us and create intance.// .hcla 阅读全文
posted @ 2012-11-13 15:23 walfud 阅读(1872) 评论(0) 推荐(0) 编辑
摘要: #define ArrLen(arr) (sizeof(arr)/sizeof(arr[0]))int main(int argc, char *argv[]){ // Open process with HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION // | PROCESS_CREATE_THREAD // Required by 'CreateRemoteThread()'. ... 阅读全文
posted @ 2012-10-23 10:46 walfud 阅读(291) 评论(0) 推荐(0) 编辑
摘要: MEMORY_BASIC_INFORMATION mbi = {}; for (unsigned char *pBase = nullptr; VirtualQuery(static_cast<void *>(pBase), &mbi, sizeof(mbi)) == sizeof(mbi); pBase += mbi.RegionSize) { if (mbi.AllocationBase == mbi.BaseAddress && mbi.AllocationBase != nullptr) { c... 阅读全文
posted @ 2012-10-23 10:35 walfud 阅读(284) 评论(0) 推荐(0) 编辑
摘要: 'HeapCreate()' s second parameter ensures there will be a region which is equal or large than 'dwInitialSize'. 阅读全文
posted @ 2012-10-15 14:13 walfud 阅读(214) 评论(0) 推荐(0) 编辑
摘要: Edit file in place: HANDLE hFile = CreateFile("dst", GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, nullptr); char *pContent = static_cast<char *>(MapViewOfFile(hFileMap, FI 阅读全文
posted @ 2012-10-12 18:03 walfud 阅读(522) 评论(0) 推荐(0) 编辑
摘要: class BoolBase{public: operator bool() const { return true; }};class A : public BoolBase{};class B : public BoolBase{};int main(int argc, char *argv[]){ if (A() == A()); // Ok. if (A() == B()); // Ok, but may NOT you want. return 0;} Just loo... 阅读全文
posted @ 2012-09-21 17:28 walfud 阅读(211) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;template <typename T>class X{ T m_val;public: friend auto operator<<(ostream &o, const X &x) -> ostream &;};template <typename T>auto operator<<(ostream &o, const X<T> &x) -> ostream &{ return o 阅读全文
posted @ 2012-09-20 19:53 walfud 阅读(203) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;template <int N>class Array{ enum class InsertOp : int { NONE, INSERTION, QUICK }; // Three insert method to choose. template <InsertOp N> class IntToType {}; // Differenciate type by this class. ... 阅读全文
posted @ 2012-09-20 14:47 walfud 阅读(185) 评论(0) 推荐(1) 编辑
摘要: #include <iostream>#include <vector>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ vector<int> v; cout <<"before: " <<v.size() <<endl; v.push_back(0); cout <<"after: " <<v.size() <<endl; cout <<"before: & 阅读全文
posted @ 2012-09-19 15:59 walfud 阅读(428) 评论(1) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;class Base{public: void foo();};class Derive : public Base{public: void foo() const { cout <<"Derive." <<endl; }};void Base::foo() // Defination of 'Base::foo' must be { static_cast<Derive *>(this)->foo();}int _tmain 阅读全文
posted @ 2012-09-18 11:03 walfud 阅读(163) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;class A{public: A() { cout <<"A::A()" <<endl; } auto foo() -> void { cout <<"A::foo(). m_x = " <<m_x <<endl; } int m_x = 100;};class B{public: B() { m_a.foo(); } // Destructive! 'm_a' has not be 阅读全文
posted @ 2012-09-14 09:55 walfud 阅读(212) 评论(0) 推荐(0) 编辑
摘要: class B{public: virtual ~B(){}};class D : public B{public: D(){}protected: virtual ~D(){}};int main(){ D d; // Illegal. B *pD = new D; // Ok. delete pD; pD = NULL; return 0;} As you see, the key is to disable create local variable by prtected access in cl... 阅读全文
posted @ 2012-09-13 19:54 walfud 阅读(143) 评论(0) 推荐(0) 编辑
摘要: Many programmers find that we can write a template constructor, but do Not know what the usage of. Let's see the coding below:class Helper{public: template <typename U> Helper(const U &other){} // Is it any meaningful? It's depends.}Intent:#include <iostream>using namespace s 阅读全文
posted @ 2012-09-13 10:24 walfud 阅读(254) 评论(0) 推荐(0) 编辑
摘要: 1. Example#include <iostream>using namespace std;class T{public: T() { cout <<"T()" <<endl; } T(const T &t) { cout <<"T(const T &t)" <<endl; } T(T &&t) { cout <<"T(T &&t)" <<endl; }};auto foo1(T && 阅读全文
posted @ 2012-08-28 17:42 walfud 阅读(369) 评论(0) 推荐(0) 编辑
摘要: usruserpasswdpasswordtmptempdmpdumpdbdatabasesrcsourcedstdestinationctorconstructordtordestructorprosconskeyvalvaluesyncsynchronousasyncasynchronousinfoinformationwarnwarningerrerrorallocallocationdeallocdeallocationacquirereleaseopt option funcfunction ptrpointer 阅读全文
posted @ 2012-08-24 14:47 walfud 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 2012/8/24 那些大师, 是不被世俗所禁锢的人. 今日去大爷家参加奶奶 80 大寿, 回家做 970 中, 看到车上有一个很糙的海报, 是培训动画制作的机构. 心想, 这么差的海报还好意思培训动画制作, 也寒碜了; 若有一张做的和变形金刚似的海报放在旁边对比... 这粗糙的海报作者何来勇气把它贴出来? 可能是自己刚学了点平面设计, 觉得已经自己这个作品已经很像市面上的还报了, 因此越看越有勇气... 我也常常如此, 看自己做的幼稚的东西, 以 "像市面上的海报" 为荣. 其实, 不经意间, 我已被世俗所禁锢... 为何那些服装设计师所做的 "衣服" 阅读全文
posted @ 2012-08-24 09:37 walfud 阅读(265) 评论(1) 推荐(0) 编辑
摘要: #include <Tlhelp32.h>#include <windows.h>#include <iostream>#include <iomanip>#include <map>#include <string>using namespace std;map<DWORD, wstring> GetProcessIdAndName(){ HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); PROCESSENTRY32 阅读全文
posted @ 2012-08-12 19:42 walfud 阅读(372) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2012-08-12 13:31 walfud 阅读(142) 评论(0) 推荐(0) 编辑
摘要: #include <Tlhelp32.h>void ListModule(DWORD pid){ HANDLE processSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid); MODULEENTRY32 me32; me32.dwSize = sizeof(MODULEENTRY32); if (Module32First(processSnap, &me32)) { do { wcout <<me32.dwSize <<endl; ... 阅读全文
posted @ 2012-08-09 09:14 walfud 阅读(610) 评论(0) 推荐(0) 编辑
摘要: GetWindowsDirectory -> c:\windows or c:\GetTempPath -> CurrentUser::%Tmp% || System::%Tmp% || CurrentUser::%Temp% || System::%Temp%SHGetKnownFolderPathDo Not use environment string for well-known directory any more, use this function instead.#include <shlobj.h>wchar_t *fullp... 阅读全文
posted @ 2012-08-08 16:56 walfud 阅读(325) 评论(0) 推荐(0) 编辑
摘要: PathFindFileNamePathFindFileName(L"c:\\windows"); // windowsPathFindFileName(L"c:\\windows\\"); // windows\PathFindFileName(L"c:"); // c:PathFindFileName(L"c:\\"); // c:\PathFindExtension/* * full path extension * c: * ... 阅读全文
posted @ 2012-08-08 16:40 walfud 阅读(588) 评论(0) 推荐(0) 编辑
摘要: BOOL IsWin7OrLater(){ // Initialization. OSVERSIONINFOEX osVerInfo = {}; osVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); osVerInfo.dwMajorVersion = 6; osVerInfo.dwMinorVersion = 1; // Set condition. DWORDLONG conditionMask = 0; int op = VER_GREATER_EQUAL; VER_SET_... 阅读全文
posted @ 2012-08-07 09:41 walfud 阅读(466) 评论(0) 推荐(1) 编辑
摘要: 毕设答辩期间长时间未接触英文, 毕业后为找感觉, 翻译此文, 以供同学们参考.walfud.2012-7-25$Id: pe.txt,v 1.7 1998/07/29 17:55:13 LUEVELSMEYER Exp $PE 文件格式===============目的-------PE(通用可执行) 文件格式是 MS windows NT, 95, win32 下的二进制可执行格式, 且在 windows NT 下, 驱动也是这个格式. 它也被能够用于对象文件和库文件.这个格式是微软设计的, 显然是基于 COFF 的良好背景知识, "常用对象文件格式" 用于 UNIX 和 阅读全文
posted @ 2012-07-25 11:56 walfud 阅读(1450) 评论(0) 推荐(0) 编辑
摘要: $Id: pe.txt,v 1.7 1998/07/29 17:55:13 LUEVELSMEYER Exp $ The PE file format================== Purpose------- The PE ("portable executable") file format is the format of executablebinaries (DLLs and ... 阅读全文
posted @ 2012-07-25 11:55 walfud 阅读(880) 评论(0) 推荐(0) 编辑
摘要: // main.cc// C++ 从 Lua 中获取变量的值. 在 Lua 5.1.4-45 测试通过.#include <iostream>#include <string>using namespace std;extern "C" {#include "lua.h"#include "lualib.h"#include "lauxlib.h"}#pragma comment(lib, "lua5.1.lib") // 这个是 Debug 版.//#pragma co 阅读全文
posted @ 2012-07-23 16:43 walfud 阅读(3289) 评论(1) 推荐(0) 编辑
摘要: 任何字符串进行数学运算时, 会自动向数字转换, 但是如果不能转换则会使程序默默退出.任何不同类型的比较, 都是 false, 如 3 ~= "3".for exp1, exp2, exp3 do <执行体> end 中, 三个表达式都是一次性求值.for 中的控制变量会被自动声明为局部变量, 并且仅在循环体内可见. i = 5 --> 全局 i. -- ..... for i=1, 3, 1 do end --> 这里的 i 是局部变量, 不是全局 i. print(i) -... 阅读全文
posted @ 2012-07-17 09:51 walfud 阅读(238) 评论(0) 推荐(0) 编辑