32 views

从模块内提取资源文件

2010年7月30日
void ExtractBinResource( HMODULE hModule, LPCTSTR lpResKind, int nResID,
	LPCTSTR lpOutFile )
{
	HGLOBAL hResourceLoaded = NULL;	// handle to loaded resource
	HRSRC hRes = NULL;				// handle/ptr. to res. info.
	LPCVOID lpResLock = NULL;	// pointer to resource data
	DWORD dwSizeRes = 0;

	// find location of the resource and get handle to it
	hRes = FindResource( hModule, MAKEINTRESOURCE(nResID), lpResKind );

	// loads the specified resource into global memory.
	hResourceLoaded = LoadResource( hModule, hRes ); 

	// get a pointer to the loaded resource!
	lpResLock = (LPCVOID)LockResource( hResourceLoaded ); 

	// determine the size of the resource,
	// so we know how much to write out to file!
	dwSizeRes = SizeofResource( hModule, hRes );

	HANDLE hFile = CreateFile(lpOutFile, GENERIC_WRITE, FILE_SHARE_READ,
		NULL,	CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	if (INVALID_HANDLE_VALUE != hFile)
	{
		WriteFile(hFile, lpResLock, dwSizeRes, &dwSizeRes, NULL);
		CloseHandle(hFile);
	}
}

free2000fly 技术心得 ,

41 views

STL bitset 简单使用示例

2010年7月29日
#include <iostream>
#include <bitset>

using namespace std;

int main()
{
	// bitset 使用整数初始化 bitset
	bitset<3> bs(7);

	// 输出 bs 各个位的值
	cout<<"bs[0] is "<<bs[0]<<endl;
	cout<<"bs[1] is "<<bs[1]<<endl;
	cout<<"bs[2] is "<<bs[2]<<endl;

	//下面的语句会抛出outofindexexception
	//cout<<"bs[3] is "<<bs[3]<<endl;

	// 使用字符串初始化 bitset
	// 注意: 使用 string 初始化时从右向左处理,
	//         如下初始化的各个位的值将是 110, 而非 011
	string strVal("011");
	bitset<3> bs1(strVal);

	// 输出各位
	cout<<"bs1[0] is "<<bs1[0]<<endl;
	cout<<"bs1[1] is "<<bs1[1]<<endl;
	cout<<"bs1[2] is "<<bs1[2]<<endl;

	// cout 输出时也是从右边向左边输出
	cout << bs1 << endl;

	// bitset 的方法
	// any() 方法如果有一位为 1, 则返回 1
	cout<<"bs1.any() = "<<bs1.any()<<endl;

	// none() 方法, 如果有一个为 1, 则 none 返回 0, 如果全为 0 则返回 1
	bitset<3> bsNone;
	cout<<"bsNone.none() = " <<bsNone.none()<<endl;

	// count() 返回几个位为 1
	cout<<"bs1.count() = "<<bs1.count()<<endl;

	// size() 返回位数
	cout<<"bs1.size() = "<<bs1.size()<<endl;

	// test() 返回某一位是否为 1

	// flip() 诸位取反
	bitset<3> bsFlip = bs1.flip();
	cout<<"bsFlip = "<<bsFlip<<endl;

	// flip(int) 将某一位取反

	// to_ulong
	unsigned long val = bs1.to_ulong();

	// reset() 方法将各个位的值都重置为 0
	bs1.reset();

	return 1;
}

free2000fly 技术心得 ,

52 views

Windows 7:”我的电脑” -> “管理” 打不开的解决方法

2010年7月26日

问题:
装好win7系统,当去掉桌面快捷方式小箭头后,在桌面计算机的管理打不开,出现“该文件没有与之关联的程序来执行操作,请执行安装程序,或者,如果已安装程序,请在‘默认程序’控制面板中创建关联”。”这样对话框,打不开,需要从控制面板中创建关联”。
解决办法:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\Manage\command]
@=hex(2):6d,00,6d,00,63,00,2e,00,65,00,78,00,65,00,20,00,63,00,6f,00,6d,00,70,\
  00,6d,00,67,00,6d,00,74,00,2e,00,6d,00,73,00,63,00,00,00

free2000fly 日常琐碎

86 views

更改 IE 代理服务器的设置

2010年7月22日

可以通过 ie 浏览器的主界面的菜单设置, “工具 -> Internet 选项 -> 连接 -> 局域网设置” 的 “代理服务器” 选项设置.

在 windows 下可以通过直接改以下注册表的方式更改代理设置, 但 IE 进程必须重启, 不是很专业.

Regedit4

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"MigrateProxy"=dword:00000001
"ProxyEnable"=dword:00000001
"ProxyHttp1.1"=dword:00000000
"ProxyServer"="http://ProxyServername:80"
"ProxyOverride"="<local>"

更好的方法是采用 InternetSetOption 函数实时改设置, 并马上对系统全局所有进程生效.
阅读全文…

free2000fly 技术心得

220 views

Setting VC++ directories in VS 2010

2010年7月13日

In VS 2010, Tools/Options does not have a VC++ directories tab (where you normally set the include/lib search folders). Instead if you take project settings for a C++ project, you’ll see VC++ Directories listed under Configuration Properties. Of course these are per project and NOT per user (as in VS 2008). If you want to change it for the current user globally, bring up the Property Manager and then you’ll see various property sheets under Debug and Release (there may be more configurations on your machine). Just edit the property sheet named Microsoft.Cpp.Win32.user and now you’ll have set it globally for your user for that specific configuration.

More:

阅读全文…

free2000fly 日常琐碎

276 views

TrueCrypt 源码

2010年7月6日

TrueCrypt 可编译版本, 主要做了一些微调, 使得能通过vs2008, 并且不再吐出警告信息, 源码TrueCrypt-6-3-a-Src 下载, 需要自己下载以下编译工具:

  • vs 2008 VS 2010 download
  • nasm 下载地址 nasm 下载后将 nasm.exe 文件解压出来, 放到 system32 目录里
  • gzip 下载地址 gzip 下载后将 gzip.exe 文件解压出来, 放到 system32 目录里
  • vc1.5 下载地址这里(本地) 下载后解压到一个文件夹, 如 d:\vc1.5 , 然后创建一个环境变量 MSVC16_ROOT = d:\vc1.5 这是微软提供的最后一个能生成 16 位代码的编译工具
  • WDK 下载地址 微软提供, 安装后用目标目录创建环境变量 BASEDIR, 如 BASEDIR = D:\WinDDK\7600.16385.1 这个工具用于编译驱动

另:

free2000fly 内核编程, 技术心得 ,

95 views

About DLGINIT in WTL

2010年7月5日

I’m using the wizard to load some static strings into a CComboBox.
When I run the app the strings aren’t visible.

Here’s what the link below says:

Initializing a Combo-Box
The ResourceView in VC++’s DevStudio allows entries in a combobox to be
added to the resource template at design time. When you add a combobox, and
bring up its properties page, then the “Data” tab is used to add entries.

When you run an MFC app and display dialogs with combo-boxes who have had
such entries defined, they are displayed with the combo-boxes populated as
expected. With WTL, the combo-boxes get displayed, but are empty. What is
happening?

Information about the combobox (such as its control id and location on the
dialog, but excluding its data entries) is stored as part of a resource, of
type DIALOG, in the resource file. The Win32 dialog APIs understand this and
load it directly before rendering the dialog. The information about the
entries in a combobox is stored as a separate resource, of type DLGINIT. The
Win32 dialog APIs do not understand DLGINIT. Other code in higher-level
libraries or the application itself has to process DLGINIT resources.

MFC provides functionality as part of its dialog classes to cater for
DLGINIT. WTL does not. The Clipcode Reuse Library contains a WTL-friendly
function called RUiDlgInit, which loads the DLGINIT data. It is modeled on
the equivalent MFC functionality.

RUiDlgInit(IDD, m_hWnd);

阅读全文…

free2000fly WTL ,

252 views

CTime 类 Format 的使用

2010年6月29日

使用 CTime 类可以很方便地取得当前系统时间并转换为各种格式

The format argument consists of one or more codes; as in printf, the formatting codes are preceded by a percent sign (%). Characters that do not begin with % are copied unchanged to strDest. The LC_TIME category of the current locale affects the output formatting of strftime.(For more information on LC_TIME, see setlocale.) The formatting codes for strftime are listed below:

阅读全文…

free2000fly 技术心得

358 views

Tips of Windows Programming

2010年6月11日

窗口总在最前

	::SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0,
		SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);

窗口总保持激活状态, 这段代码可以放在定时器内.

void KeepWindowAlwaysActive(HWND hWnd)
{
	HWND hCurWnd = NULL;
	DWORD lMyID = 0;
	DWORD lCurID = 0;

	hCurWnd = ::GetForegroundWindow();
	if(hCurWnd != hWnd)
	{
		lMyID = ::GetCurrentThreadId();
		lCurID = ::GetWindowThreadProcessId(hCurWnd, NULL);
		::AttachThreadInput(lMyID, lCurID, TRUE);
		::SetForegroundWindow(hWnd);
		::AttachThreadInput(lMyID, lCurID, FALSE);
	}
}

怎么跟自旋锁打交道

The code within a critical region guarded by an spin lock must neither be pageable nor make any references to pageable data.
The code within a critical region guarded by a spin lock can neither call any external function that might access pageable data or raise an exception, nor can it generate any exceptions.
The caller should release the spin lock with KeReleaseSpinLock as quickly as possible.

阅读全文…

free2000fly 内核编程, 技术心得 , , , ,

164 views

驱动开发中应该注意的事项

2010年6月10日

1. 一定不要在没有标注 I/O 请求数据包 (IRP) 挂起 (IoMarkIrpPending) 的情况下通过调度例程返回 STATUS_PENDING。
2. 一定不要通过中断服务例程 (ISR) 调用 KeSynchronizeExecution。 它会使系统死锁。
3. 一定不要将 DeviceObject->Flags 设置为 DO_BUFFERED_IO 和 DO_DIRECT_IO。 它会扰乱系统并最终导致致命错误。 而且,一定不要在 DeviceObject->Flags 中设置 METHOD_BUFFERED、METHOD_NEITHER、METHOD_IN_DIRECT 或 METHOD_OUT_DIRECT,因为这些值只在定义 IOCTL 时使用。
4. 一定不要通过页面缓冲池分配调度程序对象。 如果这样做,将会偶尔导致系统故障检测 (Bugcheck)。
5. 当运行于 IRQL >= DISPATCH_LEVEL 时,一定不要通过页面缓冲池分配内存,或访问页面缓冲池中的内存。 这是一个致命错误。
6. 一定不要在 IRQL >= DISPATCH_LEVEL 上等候核心调度程序对象出现非零间隔。 这是一个致命错误。
7. 在 IRQL >= DISPATCH_LEVEL 上执行时,一定不要调用任何导致调用线程发生直接或间接等待的函数。 这是一个致命错误。
8. 一定不要把中断请求级别 (IRQL) 降低到低于您的顶级例程被调用的级别。
9. 如果没有调用过 KeRaiseIrql(),则一定不要调用 KeLowerIrql()。
10. 一定不要使处理器 (KeStallExecutionProcessor) 停止运转的时间超过 50 微秒。
11. 一定不要使旋转锁 (Spin Lock) 保持锁定状态的时间超过您的需要。 要使系统获得更好的总体性能,请不要使任何系统范围内有效的旋转锁的锁定时间超过 25 微秒。
12. 当 IRQL 大于 DISPATCH_LEVEL 时,一定不要调用 KeAcquireSpinLock 和 KeReleaseSpinLock,或 KeAcquireSpinLockAtDpcLevel 和 KeReleaseSpinLockFromDpcLevel。
阅读全文…

free2000fly 内核编程, 技术心得