@ECHO OFF
TITLE=创建资源DLL文件
REM 源文件
SET SRCFILE=resource.rc
SET SCPP=RES.CPP
SET SRESH=Resource.h
REM 目标文件
SET TRESFILE=resource.res
SET TDLL=res.dll
REM 临时OBJ文件
SET TOBJ=RES.OBJ
REM 临时路径
SET OUTTMPPATH=TMP
ECHO %~A1|FIND /I "D">NUL
IF ERRORLEVEL 1 (
REM 拖放的是文件,而不是文件夹 File
GOTO ERROR
)
CALL :SETVC
ECHO.
ECHO.
REM 文件版本号
SET /P SVER=请输入DLL版本号(默认为:1.0.0.1):
MORE +320 %~FS0>%TEMP%./CreateRCFile.js
REM Folder
CSCRIPT /nologo %TEMP%./createRCFile.js "%SVER%" "%~F1./%SRCFILE%"
CD /D "%~FS1">NUL
CD ..
MOVE /Y "%~F1/%SRCFILE%" "%SRCFILE%""
IF NOT EXIST "%OUTTMPPATH%" (
MD %OUTTMPPATH%>NUL
)
ECHO 生成RES文件
REM 生成Resource.h文件
IF EXIST "%SRESH%" (
DEL /Q "%SRESH%">NUL
)
FOR /F "DELIMS=@# TOKENS=*" %%I IN ('FINDSTR /B "@#" %~FS0') DO (
ECHO %%I>>%SRESH%
)
REM 编译RC文件
RC /fo%OUTTMPPATH%/%TRESFILE% %SRCFILE%
IF ERRORLEVEL 1 GOTO ErrorMsg
ECHO 生成OBJ文件
IF EXIST "%SCPP%" (
DEL /Q "%SCPP%">NUL
)
FOR /F "DELIMS=@@ TOKENS=*" %%I IN ('FINDSTR /B "@@" %~FS0') DO (
ECHO %%I>>%SCPP%
)
CL /nologo /c %SCPP% /Fo%OUTTMPPATH%/%TOBJ%
IF ERRORLEVEL 1 GOTO ErrorMsg
ECHO 生成DLL文件
LINK /nologo ./%OUTTMPPATH%/%TOBJ% ./%OUTTMPPATH%/%TRESFILE% /dll /machine:x86 /out:%TDLL%
IF ERRORLEVEL 1 GOTO ErrorMsg
ECHO.
ECHO 所有步骤OK
ECHO.
CALL :Clean
CALL :ShowAuthor
PAUSE
EXIT
REM *******************************
:Clean
IF EXIST "%OUTTMPPATH%" RD /S /Q "%OUTTMPPATH%">NUL
IF EXIST "%SCPP%" DEL /Q "%SCPP%">NUL
IF EXIST "%SRCFILE%" DEL /Q "%SRCFILE%">NUL
IF EXIST "Resource.h" DEL /Q "Resource.h">NUL
GOTO :EOF
REM *******************************
:Error
COLOR 0C
ECHO.
ECHO 使用方法:
ECHO 将包含资源的文件夹拖放到%~NX0上即可。
ECHO.
ECHO.
CALL :ShowAuthor
PAUSE
GOTO :EOF
REM ******************************
:ErrorMsg
CALL :ShowAuthor
SET /P AN=是否清除临时文件(默认清除Y/N)?
IF /I "%AN%"=="y" CALL :Clean
GOTO :EOF
@@#include <windows.h>
@@BOOL APIENTRY DllMain( HANDLE hModule,
@@ DWORD ul_reason_for_call,
@@ LPVOID lpReserved
@@ )
@@{
@@ return TRUE;
@@}
@#//{{NO_DEPENDENCIES}}
@#// Microsoft Developer Studio generated include file.
@#// Used by NewRew.rc
@#//
@#// Next default values for new objects
@#//
@##ifdef APSTUDIO_INVOKED
@##ifndef APSTUDIO_READONLY_SYMBOLS
@##define _APS_NEXT_RESOURCE_VALUE 101
@##define _APS_NEXT_COMMAND_VALUE 40001
@##define _APS_NEXT_CONTROL_VALUE 1000
@##define _APS_NEXT_SYMED_VALUE 101
@##endif
@##endif
::*****************************************************************************
:ShowAuthor
ECHO.
ECHO ----------------------------------------------------------------------
ECHO * File name : %~nx0
ECHO * Last Update : %~t0
ECHO * version : 1.0
ECHO * Author : Hongjun Ge
ECHO * QQ : 44173555
ECHO * ICQ : 162998098
ECHO * EMail : sdhongjun@163.com
ECHO ----------------------------------------------------------------------
ECHO.
GOTO :EOF
REM 设置VC环境变量
:SETVC
SET INCLUDE=
SET LIB=
SET MSVCROOTKEY=HKLM/SOFTWARE/Microsoft/VisualStudio
SET MSVC6KEY=%MSVCROOTKEY%/6.0/Setup/Microsoft Visual C++
SET MSVC71KEY=%MSVCROOTKEY%/7.1/Setup/VC
SET MSVC8KEY=%MSVCROOTKEY%/8.0/Setup/VC
SET MSVC8EXPRESSKEY=HKLM/SOFTWARE/Microsoft/VCExpress/8.0/Setup/VC
SET MSVC9KEY=%MSVCROOTKEY%/9.0/Setup/VC
SET MSVC9EXPRESSKEY=HKLM/SOFTWARE/Microsoft/VCExpress/9.0/Setup/VC
REM First see if we can find MSVC, then set the variable
REM NOTE: delims=<tab><space>
REM NOTE: run the initial REQ QUERY outside of the if() to set ERRORLEVEL correctly
REG QUERY "%MSVC6KEY%" /v ProductDir >nul 2>nul
if "%VC6DIR%"=="" (
IF %ERRORLEVEL% EQU 0 (
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "%MSVC6KEY%" /v ProductDir') DO SET VC6DIR=%%B
)
)
REG QUERY "%MSVC71KEY%" /v ProductDir >nul 2>nul
if "%VC71DIR%"=="" (
IF %ERRORLEVEL% EQU 0 (
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "%MSVC71KEY%" /v ProductDir') DO SET VC71DIR=%%B
)
)
REG QUERY "%MSVC8KEY%" /v ProductDir >nul 2>nul
if "%VC8DIR%"=="" (
IF %ERRORLEVEL% EQU 0 (
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "%MSVC8KEY%" /v ProductDir') DO SET VC8DIR=%%B
)
)
REG QUERY "%MSVC8EXPRESSKEY%" /v ProductDir >nul 2>nul
if "%VC8EXPRESSDIR%"=="" (
IF %ERRORLEVEL% EQU 0 (
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "%MSVC8EXPRESSKEY%" /v ProductDir') DO SET VC8EXPRESSDIR=%%B
)
)
REG QUERY "%MSVC9KEY%" /v ProductDir >nul 2>nul
if "%VC9DIR%"=="" (
IF %ERRORLEVEL% EQU 0 (
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "%MSVC9KEY%" /v ProductDir') DO SET VC9DIR=%%B
)
)
REG QUERY "%MSVC9EXPRESSKEY%" /v ProductDir >nul 2>nul
if "%VC9EXPRESSDIR%"=="" (
IF %ERRORLEVEL% EQU 0 (
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "%MSVC9EXPRESSKEY%" /v ProductDir') DO SET VC9EXPRESSDIR=%%B
)
)
REM Look for Installed SDKs:
SET SDKROOTKEY=HKLM/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs
SET SDK2003SP1KEY=%SDKROOTKEY%/8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3
SET SDK2003SP2KEY=%SDKROOTKEY%/D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1
SET SDK6KEY=HKLM/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v6.0/WinSDKBuild
REM Just a base value to compare against
SET SDKVER=0
SET SDKMINORVER=0
REG QUERY "%SDK6KEY%" /v InstallationFolder >nul 2>nul
if "%SDKDIR%"=="" (
IF %ERRORLEVEL% EQU 0 (
FOR /F "tokens=2* usebackq delims= " %%A IN (`REG QUERY "HKLM/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v6.0/WinSDKBuild" /v InstallationFolder`) DO SET SDKDIR=%%B
SET SDKVER=6
)
)
REG QUERY "%SDK2003SP2KEY%" /v "Install Dir" >nul 2>nul
if "%PSDKDIR%"=="" (
IF %ERRORLEVEL% EQU 0 (
FOR /F "tokens=3* delims= " %%A IN ('REG QUERY "%SDK2003SP2KEY%" /v "Install Dir"') DO SET PSDKDIR=%%B
REM arbitrary, but works for me
SET PSDKVER=5
)
)
REG QUERY "%SDK2003SP1KEY%" /v "Install Dir" >nul 2>nul
if "%PSDKDIR%"=="" (
IF %ERRORLEVEL% EQU 0 (
FOR /F "tokens=3* delims= " %%A IN ('REG QUERY "%SDK2003SP1KEY%" /v "Install Dir"') DO SET PSDKDIR=%%B
SET PSDKVER=4
)
)
ECHO Visual C++ 6 directory: %VC6DIR%
ECHO Visual C++ 7.1 directory: %VC71DIR%
ECHO Visual C++ 8 directory: %VC8DIR%
ECHO Visual C++ 8 Express directory: %VC8EXPRESSDIR%
ECHO Visual C++ 9 directory: %VC9DIR%
ECHO Visual C++ 9 Express directory: %VC9EXPRESSDIR%
if "%SDKDIR%"=="" (
SET SDKDIR=%PSDKDIR%
SET SDKVER=%PSDKVER%
) else (
ECHO Windows SDK directory: %SDKDIR%
ECHO Windows SDK version: %SDKVER%.%SDKMINORVER%
)
ECHO Platform SDK directory: %PSDKDIR%
ECHO Platform SDK version: %PSDKVER%
if "%VC9DIR%"=="" (
if "%VC9EXPRESSDIR%"=="" (
REM 尝试MSVC8.0
if "%VC8DIR%"=="" (
REM 尝试使用MSVC7.1
if "%VC71DIR%"=="" (
REM 尝试使用MSVC6.0
if "%VC6DIR%"=="" (
ECHO 未安装VC
) else (
call "%VC6DIR%/Bin/vcvars32.bat"
)
) else (
call "%VC71DIR%/Bin/vcvars32.bat"
)
) else (
call "%VC8DIR%/Bin/vcvars32.bat"
)
)
if "%SDKDIR%"=="" (
ECHO "Microsoft Platform SDK was not found. Exiting."
pause
EXIT /B 1
)
rem Prepend MSVC paths
call "%VC9EXPRESSDIR%/Bin/vcvars32.bat"
rem Don't set SDK paths in this block, because blocks are early-evaluated.
rem Fix problem with VC++Express Edition
if "%SDKVER%"=="6" (
rem SDK Ver.6.0 (Windows Vista SDK) and 6.1 (Windows Server 2008 SDK)
rem does not contain ATL header files too.
rem It is needed to use Platform SDK's ATL header files.
SET USEPSDKATL=1
rem SDK ver.6.0 does not contain OleAcc.idl
rem It is needed to use Platform SDK's OleAcc.idl
if "%SDKMINORVER%"=="0" (
SET USEPSDKIDL=1
)
)
) else (
rem Prepend MSVC paths
call "%VC9DIR%/Bin/vcvars32.bat"
)
IF "%INCLUDE%"=="" (
ECHO.
ECHO 未安装VC环境
ECHO。
PAUSE
EXIT
)
GOTO :EOF
main();
var fso;
var sRootPath;
var sRootName;
var sRCName;
//参数0: 输入的版本号
//参数1: 输出RC文件
function main()
{
try
{
var Args = WScript.Arguments;
if (Args.length == 0)
{
WScript.Echo("未传入参数!");
return;
}
if (Args.length != 2)
{
WScript.Echo("参数数量错误!");
return;
}
var reVer = /^/d{1,2}./d{1,2}./d{1,4}./d{1,4}$/gi;
var sVer = Args(0)
if (!reVer.test(Args(0)))
{
WScript.Echo("错误的版本号,使用默认版本号:1.0.0.1代替!");
sVer = "1.0.0.1";
}
var sRCPre = new String(getRCPre());
sVer = sVer.replace(//./gi, ", ");
sRCPre = sRCPre.replace(//$/gi, sVer);
fso = new ActiveXObject("Scripting.FileSystemObject");
var fRC = fso.CreateTextFile(Args(1), true, -1);
sRCName = fso.GetFileName(Args(1));
fRC.WriteLine(sRCPre);
var rootFolder = fso.GetFolder(fso.GetParentFolderName(Args(1)));
sRootPath = rootFolder + "//";
sRootName = rootFolder.Name + "//";
EnumAll(rootFolder, fRC, true);
fRC.WriteLine(getRCSuf());
//枚举文件
fRC.close();
} catch (e) {
WScript.Echo("错误描述:" + e.description);
}
}
function EnumAll(fo, fRC, bSearchSub)
{
try
{
var rootFolder;
rootFolder = fso.GetFolder(fo);
var folderPath = rootFolder.Path;
var folderName = rootFolder.Name;
//根目录中部分目录不枚举
var parentFolderName = fso.GetParentFolderName(fo);
if ((parentFolderName != "") &&
(parentFolderName.charAt(parentFolderName.length-1) == "//"))
{
var folderNameTmp = rootFolder.Name;
if ((folderNameTmp == "RECYCLER") ||
(folderNameTmp == "Recycled") ||
(folderNameTmp == "System Volume Information")) return;
}
WScript.Echo("当前目录:" + fo);
var fc = new Enumerator(rootFolder.files);
for (; !fc.atEnd(); fc.moveNext())
{
if (fc.item().Name == sRCName) continue;
WScript.Echo("文件:" + fc.item().Name);
var file = fc.item();
var fileName = file.Name;
var sFilePath = file.ParentFolder.Path + "";
sFilePath = sFilePath.replace(sRootPath, "");
try
{
fRC.WriteLine(fileName + "/t" + rootFolder.Name + "/t/"" + sRootName + sFilePath + fileName + "/"");
}catch (e) {
WScript.Echo("");
WScript.Echo("错误描述:" + e.description);
}
}
WScript.Echo("");
if (!bSearchSub) return;
fc = new Enumerator(rootFolder.SubFolders);
for (; !fc.atEnd(); fc.moveNext())
{
EnumAll(fc.item(), fRC, false);
}
} catch (e) {
WScript.Echo("");
WScript.Echo("错误描述:" + e.description);
}
}
function getRCPre()
{
var sRet = new String("/
//Microsoft Developer Studio generated resource script./r/n/
///r/n/
#include /"resource.h/"/r/n/
/r/n/
#define APSTUDIO_READONLY_SYMBOLS/r/n/
//r/n/
///r/n/
// Generated from the TEXTINCLUDE 2 resource./r/n/
///r/n/
#include /"afxres.h/"/r/n/
/r/n/
//r/n/
#undef APSTUDIO_READONLY_SYMBOLS/r/n/
/r/n/
//r/n/
// Chinese (P.R.C.) resources/r/n/
/r/n/
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)/r/n/
#ifdef _WIN32/r/n/
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED/r/n/
#pragma code_page(936)/r/n/
#endif //_WIN32/r/n/
/r/n/
#ifdef APSTUDIO_INVOKED/r/n/
//r/n/
///r/n/
// TEXTINCLUDE/r/n/
///r/n/
/r/n/
1 TEXTINCLUDE DISCARDABLE /r/n/
BEGIN/r/n/
/"resource.h//0/"/r/n/
END/r/n/
/r/n/
2 TEXTINCLUDE DISCARDABLE /r/n/
BEGIN/r/n/
/"#include /"/"afxres.h/"/"//r//n/"/r/n/
/"//0/"/r/n/
END/r/n/
/r/n/
3 TEXTINCLUDE DISCARDABLE /r/n/
BEGIN/r/n/
/"#define _AFX_NO_SPLITTER_RESOURCES//r//n/"/r/n/
/"#define _AFX_NO_OLE_RESOURCES//r//n/"/r/n/
/"#define _AFX_NO_TRACKER_RESOURCES//r//n/"/r/n/
/"#define _AFX_NO_PROPERTY_RESOURCES//r//n/"/r/n/
/"//r//n/"/r/n/
/"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)//r//n/"/r/n/
/"#ifdef _WIN32//r//n/"/r/n/
/"LANGUAGE 9, 1//r//n/"/r/n/
/"#pragma code_page(1252)//r//n/"/r/n/
/"#endif //_WIN32//r//n/"/r/n/
/"#include /"/"afxres.rc/"/" // Standard components//r//n/"/r/n/
/"#endif//r//n/"/r/n/
/"//0/"/r/n/
END/r/n/
/r/n/
#endif // APSTUDIO_INVOKED/r/n/
/r/n/
/r/n/
#ifndef _MAC/r/n/
//r/n/
///r/n/
// Version/r/n/
///r/n/
/r/n/
VS_VERSION_INFO VERSIONINFO/r/n/
FILEVERSION $/r/n/
PRODUCTVERSION $/r/n/
FILEFLAGSMASK 0x3fL/r/n/
#ifdef _DEBUG/r/n/
FILEFLAGS 0x1L/r/n/
#else/r/n/
FILEFLAGS 0x0L/r/n/
#endif/r/n/
FILEOS 0x4L/r/n/
FILETYPE 0x2L/r/n/
FILESUBTYPE 0x0L/r/n/
BEGIN/r/n/
BLOCK /"StringFileInfo/"/r/n/
BEGIN/r/n/
BLOCK /"080404b0/"/r/n/
BEGIN/r/n/
VALUE /"Comments/", /"包含资源的动态库文件 制作:葛红军//0/"/r/n/
VALUE /"CompanyName/", /"西安市春秋视讯技术有限责任公司//0/"/r/n/
VALUE /"FileDescription/", /"资源动态库文件//0/"/r/n/
VALUE /"FileVersion/", /"$//0/"/r/n/
VALUE /"InternalName/", /"Resource DLL//0/"/r/n/
VALUE /"LegalCopyright/", /"(C) 2009 西安市春秋视讯技术有限责任公司//0/"/r/n/
VALUE /"LegalTrademarks/", /"XI'AN CHUN QIUOPTO-ELECTRONIC CO., LTD.//0/"/r/n/
VALUE /"OriginalFilename/", /"Resource.DLL//0/"/r/n/
VALUE /"PrivateBuild/", /"//0/"/r/n/
VALUE /"ProductName/", /"ResourceDLL Dynamic Link Library//0/"/r/n/
VALUE /"ProductVersion/", /"$//0/"/r/n/
VALUE /"SpecialBuild/", /"//0/"/r/n/
END/r/n/
END/r/n/
BLOCK /"VarFileInfo/"/r/n/
BEGIN/r/n/
VALUE /"Translation/", 0x804, 1200/r/n/
END/r/n/
END/r/n/
/r/n/
#endif // !_MAC/r/n/
");
return sRet;
}
function getRCSuf()
{
var sRet = new String("/
#endif // Chinese (P.R.C.) resources/r/n/
//r/n/
/r/n/
/r/n/
/r/n/
#ifndef APSTUDIO_INVOKED/r/n/
//r/n/
///r/n/
// Generated from the TEXTINCLUDE 3 resource./r/n/
///r/n/
#define _AFX_NO_SPLITTER_RESOURCES/r/n/
#define _AFX_NO_OLE_RESOURCES/r/n/
#define _AFX_NO_TRACKER_RESOURCES/r/n/
#define _AFX_NO_PROPERTY_RESOURCES/r/n/
/r/n/
//r/n/
#endif // not APSTUDIO_INVOKED /r/n/
");
return sRet;
}