Chinaunix首页 | 论坛 | 博客
  • 博客访问: 852336
  • 博文数量: 158
  • 博客积分: 4380
  • 博客等级: 上校
  • 技术积分: 2367
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-21 10:45
文章分类

全部博文(158)

文章存档

2012年(158)

我的朋友

分类: C/C++

2012-11-23 15:27:25

专门保存代码片断

阅读(9412) | 评论(66) | 转发(0) |
给主人留下些什么吧!~~

网友评论2012-11-23 15:30:23

周星星
// 手工
ifstream ifs("source",ios::binary);
ofstream ofs("target",ios::binary);
for( char buf[4096]; ifs.read(buf,sizeof(buf)/sizeof(buf[0])), ifs.gcount()!=0 && ofs.write(buf,ifs.gcount()); );
// 算法
copy( istreambuf_iterator<char>(ifstream("source",ios::binary))
    , istreambuf_iterator<char>()
    , ostreambuf_iterator<char>(ofstream("target",ios::bi

网友评论2012-11-23 15:30:13

周星星

#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
#include <iomanip>
#include <list>
#pragma comment(lib, "psapi")

bool GetProcessList( std::list<PROCESSENTRY32>& pcslst )
{
    pcslst.clear();

    HANDLE hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
    if( hProcessSnap != INVALI

网友评论2012-11-23 15:30:01

周星星
建一个win32 dll空的工程,加入如下两个文件
//a.cpp
extern "C" __declspec(dllexport) int __stdcall test( int a, int b )
{
    return a+b;
}

//a.def
LIBRARY a
EXPORTS
    test @1

然后编译联结就得到 a.dll。
附:
a. 用 depends.exe 可以查看其导出函数。
b. 如果是vc8,需要打开工程属性页 configuration properties->Linker->Input->Module Definition File输入a.def
c. 如果需要进程线程控制,加入如下函数
BOOL API

网友评论2012-11-23 15:29:43

周星星

#include <stdio.h>
#include <assert.h>
#include <windows.h>

HANDLE hInput;
HANDLE hOutput;
CONSOLE_CURSOR_INFO cursor_info;
CONSOLE_SCREEN_BUFFER_INFO screen_info;
DWORD mode;

// 设置控制台
void Init( void )
{
    // 得到控制台输入输出句柄
    hInput  = ::GetStdHandle(STD_INPUT_HANDLE);
    hOutput = ::GetStdHandle(STD_OUTPUT_HAN

网友评论2012-11-23 15:29:23

周星星

//#include <stdio.h>
//#include <conio.h>
//
//int main( )
//{
//    for( ; ; )
//    {
//        int n = _getch();
//        switch( n )
//        {
//        case 0x00:
//        case 0xE0:
//