#include <windows.h>
main()
{
HKEY hkey ;
char iepath[256];
LONG Size = 256;
if(RegOpenKeyA(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE",
&hkey) == ERROR_SUCCESS)
{
if(RegQueryValueA(hkey,
NULL,
iepath,
&Size) == ERROR_SUCCESS)
{
printf("%s",iepath);
}
}
}
这是个读取注册表程序,调用了winapi里的RegOpenKeyA函数。
直接用tcc -run reg.c不能直接运行,提示函数未定义。
查询winapi32帮助,知道RegOpenKeyA函数在advapi32.dll中,编译的时候需要添加advapi32.dll调用。
在tcc-win32.txt文档(tcc的doc文件夹)中,有两种办法:
1.用tiny_impdef将advapi32.dll生成advapi32.def文件,放在源文件同一文件夹,编译的时候用:
tcc -run reg.c advapi32.def
2.From the windows headers, only a minimal set is included. If you needmore, get MinGW's "w32api" package.
http://www.mingw.org/
找到w32api后,提取里面的lib文件夹的libadvapi32.a文件,放到tcc的lib文件夹下。
tcc的帮助tcc-doc.html文档中,对-llib参数描述如下:
`-lxxx'
Link your program with dynamic library libxxx.so or static library libxxx.a. The library is searched in the paths specified by the `-L' option.
所以可以用如下方式调用:
tcc -ladvapi32 -run reg.c
不带-run参数可生成可执行文件。