便便代码人生

关注技术, 偶尔动动手

Archive for the 'C/C++' Category

C/C++

[原] Total Commander Service to show/hide TC by hotkey/boss key/shortcut key

Posted by bianbian on 2009-03-17 02:48


本文Tags: , ,

Total Commander Service is a NT service, which supports:
1. Auto-launch TC when starting Windows
2. Hotkey: Win+Q to show/hide TC, or start TC when exit

Please put the TotalCMDService.exe (52K) in TC’s directory, and run to install/uninstall the NT service.

Tips, the best configuration:
Operation:
Check “Allow only 1 copy of Total Commander at a time”
Uncheck “Move icon to system tray when minimized”

Feel free to modify or distribute this code in any medium as long as these following two lines remain unchanged:
Total Commander Service, by bianbian.org@gmail.com
http://bianbian.org/technology/336.html

Download exe:TotalCmdService.zip (22K) , and src:TotalCmdServiceSrc.zip (10K, VC++6.0)

标签: , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, Technology, Windows | 7 Comments »

[原] 自制Total Commander自动启动和呼出热键

Posted by bianbian on 2009-03-16 08:25


本文Tags: , ,

经历多次安装卸载安装卸载,我这次终于静下心来琢磨了一下传说中的Total Commander。
总算有点上手了,确实方便,尤其现在内存大,根本不在乎耗多少资源。哈哈
不过郁闷的是这个玩意定义了那么多快捷键,却不支持呼出自己的快捷键。。。
好吧,我写个了windows NT 服务,来启动Total Commander。。。
同时注册了个全局热键(快捷键):Win+Q 来呼出Total Commander
Win+Q:T400的键盘这两个键,对我的手来说刚好是左手拇指和小指很舒服的位置。如果要改您下源码改吧
在注册表里扫了一遍,居然没有total commander的任何信息,果然绿色。
好吧,我承认,现在由于忙的关系,这个服务只做了个框。。。。过几天发布。。。。
补充:
好吧,发布了,嘿嘿:[原] Total Commander Service to show/hide TC by hotkey/boss key/shortcut key
1. 是系统服务(意味着没登录就启动TC了)
2. Win+Q隐藏或者呼出TC
下载到TC的目录里运行,安装/反安装(第一次运行安装,第二次卸载,。。。)。
由于是系统服务(默认用户是LocalSystem),如果直接启动TC也将以LocalSystem的身份运行,会带来很多问题(比如输入法就启动不了了)。
因此程序调用API(LogonUser)先进行了模拟登录,所以安装的时候需要输入用户密码。

Download exe:TotalCmdService.zip (22K) , and src:TotalCmdServiceSrc.zip (10K, VC++6.0)

标签: , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, Technology, Windows | 11 Comments »

[原] 根据struct生成基于JSON-C的json_object代码(auto generate function of C struct to JSON)

Posted by bianbian on 2008-04-09 11:13


本文Tags: ,

上次讨论了C的struct结构体与JSON交互,并提出了能否自动把struct转为JSON的问题。
今天我总算解决了这个问题,虽然中间也想过传参数给一个函数集中处理,不过都是比较麻烦。我写了一个脚本,自动生成把struct的成员插入json_object的函数,底下页面有演示:auto generate function of C struct to JSON

标签: ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, Technology | 6 Comments »

[原] 未来分布式BBS的可能实现架构

Posted by bianbian on 2008-04-04 02:22


本文Tags: ,

libevent

http://www.monkey.org/~provos/libevent/

memcached

http://www.danga.com/memcached

libmemcached

http://tangent.org/552/libmemcached.html

memcachedb (新浪博客技术团队,赞一个)

http://memcachedb.org/

ncache (同上)

http://code.google.com/p/ncache/

标签: ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, Technology | No Comments »

[原] IDL剪贴板绘图在其他语言调用下失效的bug

Posted by bianbian on 2008-03-26 02:32


本文Tags: , , ,

经过运行剪贴板监视器程序,我确认这是IDL的bug:如果用VC等其他语言调用IDL绘图,IDL并不能通过IDLgrClipboard对象将绘图结果保存到系统剪贴板(而在IDL的编辑器环境下运行,剪贴板是能得到绘图结果的)。
下面是英文描述:
IDLgrClipboard not works in callable mode (I use VC++ to execute IDL procedure to draw some plots, and copy the result to system clipboard). After running a system-clipboard-viewer-tool, I conclude it must be a bug (I tested with IDL6.2, IDL7.0).

oClipbrd = OBJ_NEW(‘IDLgrClipboard’, DIMENSIONS=windowSize)
oClipbrd->Draw, oView

It works well under IDL-workbench, but when call from VC++, everything else goes OK except clipboard is empty.

解决办法:只好制定FILENAME参数,将结果保存到文件:
Finally, I have no choise but to save the drawing to a file, and it works:

oClipbrd->Draw, oView, FILENAME=’tempout.bmp’

标签: , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, ENVI & IDL, Technology | No Comments »

[原] 模仿Google Map的FY2C实时云图平台上线~

Posted by bianbian on 2008-03-25 10:03


本文Tags: ,

模仿Google Map(图片切片载入在此平台不需要实现):

支持IE、Firefox等,支持鼠标移动、鼠标双击放大(左键)缩小(右键)、鼠标滚轮放大缩小

云图实时处理和发布(因为在学校内网,实时版本大家不能看到啦)

这里贴下演示地址(只有最后两个时次的图片):FY2C实时云图平台演示

标签: ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, JavaScript, Meteorology, Technology | No Comments »

[原] 自定义IDL调色板指南

Posted by bianbian on 2008-03-21 12:06


本文Tags: , ,

IDL的调色板功能很好很强大,以至于我还没琢磨透到底怎么调。。。。

不过一般都是用自己定义的调色板,就讲讲怎么往IDL里加入自己的调色板:
(加了以后在系统内LOADCT的时候,就能直接读取自定义的调色板,非常方便)

IDL提供了 MODIFYCT 命令用来更改或加入系统的预定义调色板:

MODIFYCT, Itab, Name, R, G, B [, FILE=filename]

Itab是索引值,0-40是系统的,一般都要41开始
Name是命名,32个字符内
R、G、B就是256长度的BYTE(单字节正数)数组
File是文件名,如果不制定就操作默认的(resouce目录的color1.tbl)

实际发现File指定了其他文件名,MODIFYCT会出错。看了源码,发现
MODIFYCT并没有处理文件读取错误(不存在)的异常。(不知道是不是IDL7.0的问题)

IDL也没有公开colortable的文件格式。不过我把MODIFYCT的源码结合color1.tbl
分析了一下,得到IDL的colortable文件格式:

总数 + R 256 + G 256 + B 256 + …. + 32长度名称(在文件末尾)

例(如果有两个表):[2][R..R][G..G][B..B][R..R][G..G][B..B][名称1][名称2]

这样就可以自己输出调色板文件了,不需要用IDL的默认文件(防止多用户冲突)。
之后可以用 LOADCT, 0, FILE=’mytable.tbl’ 动态载入

附C语言输出调色板文件代码:

  1. FILE *fp = fopen(file, "wb");
  2. BYTE n = 1;
  3. fwrite(&n, 1, 1, fp);
  4. fwrite(m_byteRGB, 1, 256 * 3, fp);
  5. fprintf(fp, "%-32s", "bianbian Default Table");
  6. fclose(fp);
标签: , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, ENVI & IDL, Technology | 2 Comments »

[原] IDL的数组存储是行顺序,下标引用是列在前

Posted by bianbian on 2008-03-17 01:29


本文Tags: , , ,

IDL的数组在内存中存储还是以行顺序的,只是多维下标引用的时候列为先。即:
A=
[r r r]
[g g g]
[b b b]
在内存中是 rrrgggbbb(和C是一样的!fortran是rgbrgbrgb)

而引用的时候列在前:(C是行在前!)
A[0,0] A[1,0] A[2,0]
A[0,1] A[1,1] A[2,1]
A[0,2] A[1,2] A[2,2]

三维的情况和C也一样(注意,IDL和C唯一的差别就是IDL的下标列在前,然后是行);存储结构一致也就意味着C里的多维数组内存块可以直接丢到IDL里处理。其实我觉得IDL在下标上太小白了,干嘛不和C保持一致?某IDL大牛说:之所以下标在前,是为了更直观的知道X方向上有几个、Y方向上有几个。比如:A[3, 2],X方向有3个,Y方向有2个(2行3列):Is IDL column-major or row-major?

某本书(似乎国内的书都不认真写 – -)说IDL是列顺序的,这是不对的。可以拿三维数据做简单试验(也便于对下标引用理解):

IDL> a=bindgen(3,3,3)
IDL> print,a
   0   1   2
   3   4   5
   6   7   8

   9  10  11
  12  13  14
  15  16  17

  18  19  20
  21  22  23
  24  25  26
IDL> print,a[1,0,*]
   1

  10

  19
IDL> print,a[*,1,1]
  12  13  14
标签: , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, ENVI & IDL, Technology | 1 Comment »

[原] 减小nginx编译后的文件大小 (Reduce file size of nginx)

Posted by bianbian on 2008-03-13 10:21


本文Tags: , , ,

默认的nginx编译选项里居然是用debug模式(-g)的(debug模式会插入很多跟踪和ASSERT之类),编译以后一个nginx有好几兆。
去掉nginx的debug模式编译,编译以后只有375K(nginx-0.5.33, gcc4)。
在 auto/cc/gcc,最后几行有:
# debug
CFLAGS=”$CFLAGS -g”
注释掉或删掉这几行,重新编译即可。-g参数用法详见这篇blog:[原]Linux下的c/c++ GDB调试

Nginx uses debug mode (-g) in compiling by default, which result in several MB of it’s size.
After debug disabled, the file size of nginx reduced to 375K (nginx-0.5.33, gcc4).
open auto/cc/gcc, find this at last several lines:
# debug
CFLAGS=”$CFLAGS -g”
delete it, and recompile. More of -g: Linux c/c++ GDB debug

标签: , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, Linux, Technology | No Comments »

[原] Intel平台gcc4,gcc3,icc测试

Posted by bianbian on 2007-09-24 12:20


本文Tags: , , , ,

[from zhch begin]
以一个简单的计算程序为例:

int main() {
double s=0;
int i;
for(i=200000001; i>=1; i-=4) s+=1.0/i-1.0/(i+2);
printf(“Pi=%f\n”, s*4);
}

这是一个常见的算Pi的程序,基本算法是Pi/4=1-1/3+1/5-1/7+…..
[from zhch end]

Slackware 12.0预装了gcc 4.1.2,我手动装了gcc 3.4.6,和icc 10.0。下面是测试结果:

bbs@bbs:~/test$ gcc -o PI.gcc PI.c -O3 -march=pentium4 -msse2 -mmmx
PI.c: In function ‘main’:
PI.c:5: warning:incompatible implicit declaration of built-in function ‘printf’

bbs@bbs:~/test$ icc -o PI.icc PI.c -O3 -xP
PI.c(5): warning #266: function “printf” declared implicitly
printf(“Pi=%f\n”, s*4);
^
PI.c(4): (col. 9) remark: LOOP WAS VECTORIZED.

bbs@bbs:~/test$ gcc3 -o PI.gcc3 PI.c -O3 -march=pentium4 -msse2 -mmmx

bbs@bbs:~/test$ time PI.gcc; time PI.gcc3; time PI.icc
Pi=3.141593

real 0m1.568s
user 0m1.544s
sys 0m0.016s
Pi=3.141593

real 0m1.551s
user 0m1.544s
sys 0m0.008s
Pi=3.141593

real 0m1.246s
user 0m1.212s
sys 0m0.012s

测试环境:Intel(R) Xeon(TM) MP CPU 3.00GHz * 4, 8G MEM

文件大小:
bbs@bbs:~/test$ v PI*
-rw-r–r– 1 bbs bbs 140 2007-09-23 22:28 PI.c
-rwxr-xr-x 1 bbs bbs 6365 2007-09-23 23:08 PI.gcc*
-rwxr-xr-x 1 bbs bbs 6343 2007-09-23 23:47 PI.gcc3*
-rwxr-xr-x 1 bbs bbs 19769 2007-09-23 23:08 PI.icc*

果然跟一些文章说的,gcc4比gcc3编译结果和运算速度都有所下降,icc在Intel平台下确实优化比较明显,毕竟是自己家的东西。

标签: , , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, Linux, Technology | 1 Comment »

[原]Linux下的c/c++ GDB调试

Posted by bianbian on 2007-09-18 10:13


本文Tags: , , ,

还是比较厉害的,比较准。
编译的时候加入 -g -rdynamic 选项,之后就可以跑调试了:
linux $ gcc -g -rdynamic -o error error.c
linux $ gdb error
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “i686-pc-linux-gnu”…Using host libthread_db library “/lib/libthread_db.so.1″.

(gdb) run
Starting program: /home/linux/error

Program received signal SIGSEGV, Segmentation fault.
错误内容
行数 源码;
(gdb) kill
(gdb) q

linux $

标签: , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, Linux, Technology | 6 Comments »

[晕] 居然还有这种东西:C++ Trigraph

Posted by bianbian on 2007-08-01 03:34


本文Tags:

听说为了照顾某些键盘坏了又换不起的,可以使用这种3字符的串来代替一些特殊字符,preprocess的时候会替换掉:

#: ??=
\: ??/
^: ??’
[: ??(
]: ??)
{: ??<
}: ??>
|: ??!
~: ??-

于是程序就这样了:

  1. //: S03:trigraph.cpp
  2. ??=include <iostream>
  3.  
  4. int main(int argc, char* argv??(??)) ??<
  5.     using namespace std;
  6.     unsigned int n;
  7.     if (argc != 2 ??!??! (n = atoi(argv??(1??))) <= 0)
  8.         return 1;
  9.     cout << ??-(n ??' 0xf0f0) << '??/n';
  10.     return 0;
  11. ??>

我就奇怪了,键盘换不起,眼睛换换就那么便宜吗?

标签:

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, Technology | 2 Comments »

[问] fwrite的问题

Posted by bianbian on 2007-07-28 12:52


本文Tags:

fwrite(const void *buffer,size_t size, size_t count, FILE *fp);
这个似乎是把内存里的一股脑儿write到文件里去。
如果buffer是new出来的一大堆数据,有可能在内存里是分片存的,这时候一大堆一起写就有问题。
我不清楚是VC6的问题,还是fwrite本来就有这个问题:

  1. ....
  2. double *_bt[k] = new double[_header.wHeight * _header.wWidth];
  3. ....
  4. for(k=0; k < _GRAY_BANDS; k++)
  5. {
  6.   //用:fwrite(_bt[k], sizeof(double), _header.wHeight * _header.wWidth, fp2); 就不对
  7.   //必须一个一个保存
  8.   for(int j=0; j < _header.wHeight; j++)
  9.   {
  10.     for(int i=0; i < _header.wWidth; i++)
  11.     {
  12.        int idx = j * _header.wHeight + i;
  13.        fwrite(& _bt[k][idx], sizeof(double), 1, fp2);
  14.     }
  15.   }
  16.   delete[] _bt[k];
  17. }
  18. fclose(fp2);

哪位经过告诉我一声。

标签:

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, Technology | 3 Comments »

[原] C的struct和JSON交互

Posted by bianbian on 2007-07-15 04:55


本文Tags: ,

经过一天努力,现在百合涂鸦板用了JSON传递数据:http://bbs.nju.edu.cn/pntdoc?board=beginner
虽然把数据和页面分开了,不过觉得过程还是比较麻烦:
1)新建JSON对象,C读取struct,把值插入
2)输出to_JSON_String
3)Javascript解析JSON,通过JST模板生成页面

实在是比较麻烦,有没有可能把一个struct直接转成JSON对象?
或者直接丢struct的字节码(加上描述信息)过去让Javascript负责解析成JSON对象?

struct就是一段长度固定的二进制码,如果想个办法能和JSON对象之间转换,应该能大大解放C作FastCGI的生产力。我的意思是这样:
C:
struct obj {
char name[3];
int age;
};

JSON:
obj {
name: “12″,
age: int
}

让我想想。

标签: ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, JavaScript, Technology | 1 Comment »

[原]C语言连接postgres的实例 – libpq使用

Posted by bianbian on 2006-12-20 03:28


本文Tags: ,

看过长篇文档后,啥废话也不说了,来个实例总结:

  1. char *sql = "SELECT userid,password FROM users WHERE ....";
  2. PGconn *conn = PQconnectdb("host=localhost user=postgres password= dbname=db port=5432");
  3. if (PQstatus(conn) == CONNECTION_OK)
  4. {
  5.   PQsetClientEncoding(conn, "UNICODE");
  6.   PGresult *res = PQexec(conn, sql);
  7.   if (res != null)
  8.   {
  9.     int status = PQresultStatus(res);
  10.     if (status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK)
  11.     {
  12.       char *res_userid = PQgetvalue(res, 0, 0);
  13.       char *res_password = PQgetvalue(res, 0, 1);
  14.       ....
  15.     }
  16.     PQclear(res);
  17.   }
  18. }
  19. PQfinish(conn);
标签: ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, Database, Technology | 2 Comments »