Posts
[C++]使用TinyXml讀寫Xml
TiXmlNode* rootElement = xmlDoc.InsertEndChild(TiXmlElement("Person")); rootElement ->InsertEndChild(TiXmlElement("Name")) ->InsertEndChild(TiXmlText(person->m_sName.c_str())); rootElement ->InsertEndChild(TiXmlElement("NickName")) ->InsertEndChild(TiXmlText(person->m_sNickName.c_str())); char buffer[256]; _itoa(person->m_nAge, buffer,10); rootElement ->InsertEndChild(TiXmlElement("Age")) ->InsertEndChild(TiXmlText(buffer)); xmlDoc.SaveFile(file.c_str()); }
xmlDoc.LoadFile(); if(xmlDoc.ErrorId() > 0) return; TiXmlElement* pRootElement = xmlDoc.RootElement(); if(!pRootElement) return; TiXmlElement* pNode = NULL; pNode = pRootElement->FirstChildElement("Name"); if(pNode) { person->m_sName = pNode->GetText(); } pNode = pRootElement->FirstChildElement("NickName"); if(pNode) { person->m_sNickName = pNode->GetText(); } pNode = pRootElement->FirstChildElement("Age"); if(pNode) { person->m_nAge = atoi(pNode->GetText()); } }
#include “stdafx.h” #include <string> #include “tinyxml.h”
#include “tinystr.
read morePosts
[C++]使用Pageheap偵測記憶體越界錯誤
pageheap Displays pageheap enabled programs
pageheap /enable PROGRAM Enables page heap for PROGRAM pageheap /enable PROGRAM FLAGS Enables page heap for PROGRAM using
FLAGS (hex number) for heap flags.
pageheap /disable PROGRAM Disables page heap for PROGRAM pageheap PROGRAM Displays current setting for PROGRAM
Example: pageheap /enable notepad pageheap /disable pbrush
Note. Enabling page heap does not affect currently running processes. If you need to use page heap for processes that are already running and cannot be restarted (csrss.
read morePosts
[C#]Enable UAC Shield icons and run as administrator
#region Private Method private static bool AtLeastVista() { return (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6); } private static void SetButtonShield(Button btn, bool showShield) { if (!AtLeastVista()) return; btn.FlatStyle = FlatStyle.System; SendMessage(new HandleRef(btn, btn.Handle), BCM_SETSHIELD, IntPtr.Zero, showShield ? new IntPtr(1) : IntPtr.Zero); } #endregion</pre> public static class ButtonExtension { #region DllImport [DllImport(“shell32.dll”, EntryPoint = “#680”, CharSet = CharSet.Unicode)] private static extern bool IsUserAnAdmin();
[DllImport("user32.dll", CharSet = CharSet.Unicode)] private static extern IntPtr SendMessage(HandleRef hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); #endregion #region Const const int BCM_SETSHIELD = 0x0000160C; #endregion #region Private Method private static bool AtLeastVista() { return (Environment.
read morePosts
[.Net concept]使用方法與屬性時適時為其值做快取
//Calculate count.... ... return count; }
int count = myObj.Count; for (int i = 0; i < count; ++i) { for (int j = 0; j < count; ++j) ... } }
read morePosts
[C++]使用ReadDirectoryChangesW API監控檔案系統的改變
hDirectoryHandle = ::CreateFileA( file, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL);
if(hDirectoryHandle == INVALID_HANDLE_VALUE) return;
memset(buffer, 0, nBufferSize);
if(!::ReadDirectoryChangesW( hDirectoryHandle, buffer, nBufferSize, bIncludeSubdirectories, FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_FILE_NAME, &dwBytes, NULL, NULL) || GetLastError() == ERROR_INVALID_HANDLE) { break; }
if(!dwBytes) { printf(“Buffer overflow~~ “); }
do { switch (record->Action) { case FILE_ACTION_ADDED: printf(“FILE_ACTION_ADDED:”); break; case FILE_ACTION_REMOVED: printf(“FILE_ACTION_REMOVED:”); break; case FILE_ACTION_MODIFIED: printf(“FILE_ACTION_MODIFIED:”); break; case FILE_ACTION_RENAMED_OLD_NAME: printf(“FILE_ACTION_RENAMED_OLD_NAME:”); break;
read morePosts
[C++]Simple nativated timer class
};
#pragma region Constructor & DeConstructor EventArgs::EventArgs(void) { }
EventArgs::~EventArgs(void) { }
#pragma endregion
[event_source] [event_receiver] class Timer { #pragma region Var private: int _nTimerID; int _nInterval; bool _bIsEnabled; #pragma endregion
#pragma region Private Property private: __declspec(property(get=Get_nTimerID,put=Set_nTimerID)) int m_nTimerID; #pragma endregion
#pragma region Public Property public: __declspec(property(get=Get_nInterval,put=Set_nInterval)) int m_nInterval;
__declspec(property(get=Get_bIsEnabled,put=Set_bIsEnabled)) bool m_bIsEnabled; #pragma endregion
#pragma region Event public: __event void IntervalChanging(void* sender, EventArgs* e); __event void IntervalChanged(void* sender, EventArgs* e); __event void IsEnabledChanging(void* sender, EventArgs* e); __event void IsEnabledChanged(void* sender, EventArgs* e); __event void Tick(void* sender, EventArgs* e); #pragma endregion
read more