|
Posted on 2008-11-04 19:27 S.l.e!ep.¢% 阅读(2235) 评论(4) 编辑 收藏 引用 所属分类: VC
为了生成 swf 方法,写了个工具,写得,写得很粗糙…… #include <string>
#include <vector>
#include <iostream>
using namespace std;
#include <windows.h>
#include <atlbase.h>
![](/Images/OutliningIndicators/None.gif)
namespace std
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](/Images/OutliningIndicators/ContractedBlock.gif) {
typedef basic_string<WCHAR, char_traits<WCHAR>, allocator<WCHAR> > tstring;
}
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) /**//*
* return a absolute path and create a temporary file
* the path is the system temp directory,
* the filename is a temporary file name contains [strTmp]
* Tips!!! Must delete the temporary file after used
*/
string getTempFilePath(string strTmp)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](/Images/OutliningIndicators/ContractedBlock.gif) {
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) TCHAR szTmpPath[_MAX_PATH] = {0}, szTmpFileName[_MAX_PATH] = {0};
![](/Images/OutliningIndicators/InBlock.gif)
DWORD dwLength = ::GetTempPath(_MAX_PATH, szTmpPath);
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) /**//*
* If the function [GetTempPath] fails, return a null string
*/
if ( dwLength == 0 )
return __TEXT("");
![](/Images/OutliningIndicators/InBlock.gif)
DWORD dwLength2 = ::GetTempFileName(szTmpPath, strTmp.c_str(), 0, szTmpFileName);
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) /**//*
* If the function [GetTempFileName] fails, return a null string
*/
if ( dwLength2 == 0 )
return __TEXT("");
![](/Images/OutliningIndicators/InBlock.gif)
return szTmpFileName;
}// _getTempFilePath()
![](/Images/OutliningIndicators/None.gif)
int main(int argc, char* argv[])
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](/Images/OutliningIndicators/ContractedBlock.gif) {
int nArgs = 0;
std::vector<std::tstring> vecToken;
![](/Images/OutliningIndicators/InBlock.gif)
LPWSTR * szArglist = ::CommandLineToArgvW(::GetCommandLineW(), &nArgs);
![](/Images/OutliningIndicators/InBlock.gif)
if( NULL == szArglist )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
cout << "Invalid Parameter!" << endl;
return 1;
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(int i = 0; i < nArgs; i++)
vecToken.push_back(szArglist[i]);
![](/Images/OutliningIndicators/InBlock.gif)
}// if( NULL == szArglist )
![](/Images/OutliningIndicators/InBlock.gif)
// Free memory allocated for CommandLineToArgvW arguments.
LocalFree(szArglist);
![](/Images/OutliningIndicators/InBlock.gif)
if ( vecToken.size() != 3 )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
cout << "Invalid Parameter! " << vecToken.size() << endl;
return 1;
}
![](/Images/OutliningIndicators/InBlock.gif)
USES_CONVERSION;
//cout << (char*)W2A(vecToken[1].c_str()) << endl;
//cout << (char*)W2A(vecToken[2].c_str()) << endl;
![](/Images/OutliningIndicators/InBlock.gif)
// 获取目标目录所有 *.fla 文件
WIN32_FIND_DATA filedata;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) char strResultLogPath[MAX_PATH] = {0};
sprintf(strResultLogPath, _T("%s\\*.fla"), W2A(vecToken[1].c_str()) );
std::vector<string> vecFlaLogs;
![](/Images/OutliningIndicators/InBlock.gif)
HANDLE hFind = ::FindFirstFile(strResultLogPath, &filedata);
if (hFind == INVALID_HANDLE_VALUE)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
// 一个 .fla 文件都没有
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
do
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
// filedata.cFileName 为 fla 的文件名
vecFlaLogs.push_back(filedata.cFileName);
OutputDebugString(filedata.cFileName);
OutputDebugString("\n");
} while( FindNextFile(hFind, &filedata) );
![](/Images/OutliningIndicators/InBlock.gif)
}// if (hFind == INVALID_HANDLE_VALUE)
::FindClose(hFind);
![](/Images/OutliningIndicators/InBlock.gif)
// 存放临时文件
string strFile = getTempFilePath("fl");
string strFile1 = strFile;
strFile += ".jsfl";
![](/Images/OutliningIndicators/InBlock.gif)
FILE* pFile = fopen(strFile.c_str(), "wb");
if ( pFile == NULL )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
cout << "failed to open file: " << strFile.c_str() << endl;
return 1;
}
![](/Images/OutliningIndicators/InBlock.gif)
std::vector<string>::iterator iter_t;
for ( iter_t = vecFlaLogs.begin(); iter_t != vecFlaLogs.end(); iter_t++ )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
string strFlaFile = *iter_t;
string strSwfFile = *iter_t;
![](/Images/OutliningIndicators/InBlock.gif)
strSwfFile = strSwfFile.substr(0, strSwfFile.length() - 4);
strSwfFile += ".swf";
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) fprintf(pFile, "var sourceFile = \"file:/**////%s/%s\";\r\n", W2A(vecToken[1].c_str()), strFlaFile.c_str());
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) fprintf(pFile, "var outputFile = \"file:/**////%s/%s\";\r\n", W2A(vecToken[2].c_str()), strSwfFile.c_str());
fprintf(pFile, "var doc = fl.openDocument(sourceFile);\r\n");
fprintf(pFile, "doc.exportSWF(outputFile, true);\r\n");
fprintf(pFile, "doc.close(false);\r\n");
![](/Images/OutliningIndicators/InBlock.gif)
}// for ( iter_t = vecFlaLogs.begin(); iter_t != vecFlaLogs.end(); iter_t++ )
![](/Images/OutliningIndicators/InBlock.gif)
fprintf(pFile, "fl.quit();\r\n");
// 关闭文件时才保存文件内容
fclose(pFile);
![](/Images/OutliningIndicators/InBlock.gif)
// 读取注册表
HKEY hk;
LPCTSTR data_Get="Flash.JSCommandFile\\shell\\open\\command";
//在注册表里的位置
long ret0 = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, //根
data_Get, 0, //必须为0,保留
KEY_READ, //安全访问屏蔽字,具体见MSDN,列出了所有的值
&hk);
//通过ERROR_SUCCESS判断打开是否成功。
if( ret0 != ERROR_SUCCESS)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
cout << "failed to read regedit" << endl;
return 1;
}
![](/Images/OutliningIndicators/InBlock.gif)
LPBYTE win_version = new BYTE[80];
DWORD type=REG_SZ;
DWORD cbData=80;
long ret1 = ::RegQueryValueEx(hk, "", //请求得到的键的名称
NULL, //保留,必须为
NULL, //值的类型,具体见MSDN
win_version, //接受值的缓冲区
&cbData); //缓冲区大小
if ( ret1 != ERROR_SUCCESS )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
cout << "failed to read regedit" << endl;
return 1;
}
![](/Images/OutliningIndicators/InBlock.gif)
string strRegValue = (char*)win_version;
delete[] win_version;
::RegCloseKey(hk);
strRegValue = strRegValue.substr(0, strRegValue.length() - 5);
![](/Images/OutliningIndicators/InBlock.gif)
// 调用 flash.exe
//strRegValue
strRegValue += " ";
strRegValue += "\"";
strRegValue += strFile;
strRegValue += "\"";
![](/Images/OutliningIndicators/InBlock.gif)
UINT rlt = WinExec(strRegValue.c_str(), SW_HIDE);
switch (rlt)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
case 0:
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
cout << "The system is out of memory or resources." << endl;
return 1;
}
break;
![](/Images/OutliningIndicators/InBlock.gif)
case ERROR_BAD_FORMAT:
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
cout << "The .exe file is invalid." << endl;
return 1;
}
break;
![](/Images/OutliningIndicators/InBlock.gif)
case ERROR_FILE_NOT_FOUND:
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
cout << "The specified file was not found." << endl;
return 1;
}
break;
case ERROR_PATH_NOT_FOUND:
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
cout << "The specified path was not found." << endl;
return 1;
}
break;
}
![](/Images/OutliningIndicators/InBlock.gif)
// 删除临时文件
::DeleteFile(strFile.c_str());
::DeleteFile(strFile1.c_str());
![](/Images/OutliningIndicators/InBlock.gif)
return 0;
}
Feedback
# re: 为了生成flash文件方便,写了个工具 回复 更多评论
2008-11-05 02:11 by
这个代码好像在www.zuiwanting.com见过
# re: 为了生成flash文件方便,写了个工具 回复 更多评论
2008-11-05 12:55 by
好像是在命令行调用什么工具来编译fla文件为swf 其实用C++写这样的功能太浪费了 用一个bat或VBS完全能搞定的
# re: 为了生成flash文件方便,写了个工具 回复 更多评论
2008-11-05 14:19 by
该页面有木马………………
最近发现cppblog好多页面都被挂了木马,大家小心一下
# re: 为了生成flash文件方便,写了个工具 回复 更多评论
2008-11-10 22:21 by
你是指这个页面有马?
晕,我没装杀毒软件啊!!!!
|