IRWConvDlg.cpp
上传用户:yatsl7111
上传日期:2007-01-08
资源大小:1433k
文件大小:26k
- // IRWConvDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "IRWConv.h"
- #include "IRWConvDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CIRWConvDlg dialog
- CIRWConvDlg::CIRWConvDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CIRWConvDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CIRWConvDlg)
- m_SouFileNameStr = _T("");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CIRWConvDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CIRWConvDlg)
- DDX_Control(pDX, IDC_FUN_REREAD_IMAGE, m_FunReReadImage);
- DDX_Control(pDX, IDC_MODULE_NAME, m_ModuleName);
- DDX_Control(pDX, IDC_FUN_SAVE_IMAGE, m_FunSaveImage);
- DDX_Control(pDX, IDC_FUN_READ_IMAGE, m_FunReadImage);
- DDX_Control(pDX, IDC_DESFN_EXIST, m_DesFileExist);
- DDX_Control(pDX, IDC_FULL_IRW, m_FillIRW);
- DDX_Control(pDX, IDC_SOU_PROCTYPE_NUM, m_ProcTypeNumber);
- DDX_Control(pDX, IDC_FILE_TYPE, m_FileType);
- DDX_Control(pDX, IDC_SOU_WRITER, m_Writer);
- DDX_Control(pDX, IDC_SOU_TYPE, m_PlugsInType);
- DDX_Control(pDX, IDC_SOU_SUBVER, m_SubVer);
- DDX_Control(pDX, IDC_SOU_PROCTYPE_STR, m_ProcTypeStr);
- DDX_Control(pDX, IDC_SOU_MODULE, m_Module);
- DDX_Control(pDX, IDC_SOU_MAJVER, m_MajVer);
- DDX_Control(pDX, IDC_SOU_HAHA, m_HaHa);
- DDX_Control(pDX, IDC_SOU_FILENAME, m_SouFileName);
- DDX_Control(pDX, IDC_SOU_EMAIL, m_EMail);
- DDX_Control(pDX, IDC_OPEN_FILE, m_OpenFile);
- DDX_Control(pDX, IDC_LOGO, m_LogoBmp);
- DDX_Control(pDX, IDC_DES_FILENAME, m_DesFileName);
- DDX_Control(pDX, IDC_CONV_TO_IRW, m_ConvToIRW);
- DDX_Control(pDX, IDC_CONV_TO_DLL, m_ConvToDLL);
- DDX_Text(pDX, IDC_SOU_FILENAME, m_SouFileNameStr);
- DDV_MaxChars(pDX, m_SouFileNameStr, 512);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CIRWConvDlg, CDialog)
- //{{AFX_MSG_MAP(CIRWConvDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_OPEN_FILE, OnOpenFile)
- ON_BN_CLICKED(IDC_CONV_TO_DLL, OnConvToDll)
- ON_BN_CLICKED(IDC_CONV_TO_IRW, OnConvToIrw)
- ON_BN_CLICKED(IDC_FULL_IRW, OnFillIrw)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CIRWConvDlg message handlers
- BOOL CIRWConvDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
- m_SouFileNameStr.Empty();
- m_SouFileName.SetWindowText((LPCTSTR)_T(""));
- m_DesFileName.SetWindowText((LPCTSTR)_T(""));
- m_DesFileName.EnableWindow(FALSE);
- m_PlugsInType.AddString((LPCTSTR)_T("内置插件"));
- m_PlugsInType.AddString((LPCTSTR)_T("外部插件"));
- m_PlugsInType.SetCurSel(0);
- m_PlugsInType.EnableWindow(FALSE);
- m_Module.AddString((LPCTSTR)_T("发布版"));
- m_Module.AddString((LPCTSTR)_T("调试版"));
- m_Module.SetCurSel(0);
- m_Module.EnableWindow(FALSE);
- m_MajVer.AddString((LPCTSTR)_T("0."));
- m_MajVer.AddString((LPCTSTR)_T("1."));
- m_MajVer.AddString((LPCTSTR)_T("2."));
- m_MajVer.AddString((LPCTSTR)_T("3."));
- m_MajVer.AddString((LPCTSTR)_T("4."));
- m_MajVer.AddString((LPCTSTR)_T("5."));
- m_MajVer.AddString((LPCTSTR)_T("6."));
- m_MajVer.AddString((LPCTSTR)_T("7."));
- m_MajVer.AddString((LPCTSTR)_T("8."));
- m_MajVer.AddString((LPCTSTR)_T("9."));
- m_MajVer.SetCurSel(0);
- m_MajVer.EnableWindow(FALSE);
- m_SubVer.AddString((LPCTSTR)_T("0"));
- m_SubVer.AddString((LPCTSTR)_T("1"));
- m_SubVer.AddString((LPCTSTR)_T("2"));
- m_SubVer.AddString((LPCTSTR)_T("3"));
- m_SubVer.AddString((LPCTSTR)_T("4"));
- m_SubVer.AddString((LPCTSTR)_T("5"));
- m_SubVer.AddString((LPCTSTR)_T("6"));
- m_SubVer.AddString((LPCTSTR)_T("7"));
- m_SubVer.AddString((LPCTSTR)_T("8"));
- m_SubVer.AddString((LPCTSTR)_T("9"));
- m_SubVer.SetCurSel(0);
- m_SubVer.EnableWindow(FALSE);
- m_ProcTypeNumber.SetWindowText((LPCTSTR)_T(""));
- m_ProcTypeNumber.EnableWindow(FALSE);
- m_ProcTypeStr.SetWindowText((LPCTSTR)_T(""));
- m_ProcTypeStr.EnableWindow(FALSE);
-
- m_Writer.SetWindowText((LPCTSTR)_T(""));
- m_Writer.EnableWindow(FALSE);
- m_EMail.SetWindowText((LPCTSTR)_T(""));
- m_EMail.EnableWindow(FALSE);
- m_HaHa.SetWindowText((LPCTSTR)_T(""));
- m_HaHa.EnableWindow(FALSE);
- m_DesFileExist.SetCheck(1);
- m_DesFileExist.EnableWindow(FALSE);
- m_FunSaveImage.SetCheck(0);
- m_FunSaveImage.EnableWindow(FALSE);
- m_FunReadImage.SetCheck(1);
- m_FunReadImage.EnableWindow(FALSE);
- m_FunReReadImage.SetCheck(0);
- m_FunReReadImage.EnableWindow(FALSE);
- m_ModuleName.SetWindowText((LPCTSTR)_T(""));
- m_ModuleName.EnableWindow(FALSE);
- m_ConvToIRW.EnableWindow(FALSE);
- m_ConvToDLL.EnableWindow(FALSE);
- m_FillIRW.EnableWindow(FALSE);
- m_State = 0;
- ZeroMemory((PVOID)&m_Info, sizeof(PLUGSIN));
- m_SouFn.Empty();
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CIRWConvDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CIRWConvDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CIRWConvDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CIRWConvDlg::OnOpenFile()
- {
- CFileDialog fd(TRUE, NULL, NULL, OFN_FILEMUSTEXIST,
- (LPCTSTR)"模块文件(*.irw; *.dll)|*.irw; *.dll|ISee图像读写插件(*.irw)|*.irw|ISee图像读写DLL(*.dll)|*.dll|所有文件(*.*)|*.*||",
- (CWnd*)this);
- CString fn;
- CString soufn;
- CString desfn;
- char drive[_MAX_DRIVE];
- char dir[_MAX_DIR];
- char fname[_MAX_FNAME];
- char ext[_MAX_EXT];
- BYTE ps[256];
- BYTE pd[32];
- INFOSTR pk;
- HMODULE m_hDll; // 模块DLL句柄
- IRWP_INTERFACE m_IRWPInterFace; // 模块DLL接口函数地址。
- if (fd.DoModal() == IDOK)
- {
- fn = fd.GetPathName();
- _splitpath((const char*)fn, drive, dir, fname, ext);
- if (!lstrcmp(ext, (LPCTSTR)".dll"))
- {
- m_hDll = ::LoadLibrary((LPCTSTR)fn);
- if (!m_hDll)
- {
- MessageBox((LPCTSTR)"您指定的DLL文件无法读入内存,请检查这个文件是否有效。",
- (LPCTSTR)"文件错误");
- return;
- }
- m_IRWPInterFace = (IRWP_INTERFACE)::GetProcAddress(m_hDll, MAKEINTRESOURCE(1));
- if (!m_IRWPInterFace)
- {
- ::FreeLibrary(m_hDll);
- MessageBox((LPCTSTR)"您指定的这个DLL文件不是ISee的图像读写模块(无法获取接口地址),请检查。",
- (LPCTSTR)"文件错误");
- return;
- }
- ::memset((void*)&pk, 0, sizeof(INFOSTR));
- pk.comm = CMD_IS_SUPPORT;
- pk.result = ER_EMPTY;
- pk.annexdata.cmAnnData = CMD_IS_SUPPORT;
- m_IRWPInterFace(&pk);
- if (pk.result != ER_SUCCESS)
- {
- ::FreeLibrary(m_hDll);
- MessageBox((LPCTSTR)"您指定的这个DLL文件不是ISee的图像读写模块,请检查它的有效性。",
- (LPCTSTR)"文件类型错误");
- return;
- }
- m_FileType.SetWindowText((LPCTSTR)_T("ISee图像读写模块DLL文件"));
- soufn.Empty();
- soufn += drive;
- soufn += "\...\";
- soufn += fname;
- soufn += ext;
- desfn.Empty();
- desfn += drive;
- desfn += dir;
- desfn += fname;
- desfn += ".irw";
- m_SouFn = fd.GetPathName();
- m_SouFileName.SetWindowText((LPCTSTR)soufn);
- m_DesFileName.SetWindowText((LPCTSTR)desfn);
- // 获取作者留言
- pk.comm = CMD_GETWRITERMESS;
- pk.result = ER_EMPTY;
- ::ZeroMemory((PVOID)pk.annexdata.scAnnData, DPK_ANNEXINFOSIZE);
- m_IRWPInterFace(&pk);
- m_HaHa.SetWindowText((LPCTSTR)pk.annexdata.scAnnData);
- m_HaHa.EnableWindow();
- // 获取作者名字
- pk.comm = CMD_GETWRITERS;
- pk.result = ER_EMPTY;
- ::ZeroMemory((PVOID)pk.annexdata.scAnnData, DPK_ANNEXINFOSIZE);
- m_IRWPInterFace(&pk);
- m_Writer.SetWindowText((LPCTSTR)pk.annexdata.scAnnData);
- m_Writer.EnableWindow();
- // 获取能处理的文件类型串
- pk.comm = CMD_GETPROCTYPE;
- pk.result = ER_EMPTY;
- ::ZeroMemory((PVOID)pk.annexdata.scAnnData, DPK_ANNEXINFOSIZE);
- m_IRWPInterFace(&pk);
- m_ProcTypeStr.SetWindowText((LPCTSTR)pk.annexdata.scAnnData);
- m_ProcTypeStr.EnableWindow();
- ::ZeroMemory((PVOID)ps, 256);
- ::ZeroMemory((PVOID)pd, 32);
- ::memcpy((void *)ps, (void *)pk.annexdata.scAnnData, ::lstrlen((LPCTSTR)pk.annexdata.scAnnData));
- int tn = _GetProcTypeData((LPTSTR)ps, (LPTSTR)pd);
- ::itoa(tn, (char*)ps, 10);
- m_ProcTypeNumber.SetWindowText((LPCTSTR)ps);
- // 获取内部版本号
- pk.comm = CMD_GETBUILDID;
- pk.result = ER_EMPTY;
- pk.annexdata.dwAnnData = 0L;
- m_IRWPInterFace(&pk);
- m_MajVer.SetCurSel(pk.annexdata.dwAnnData/10);
- m_SubVer.SetCurSel(pk.annexdata.dwAnnData-(pk.annexdata.dwAnnData/10)*10);
- m_MajVer.EnableWindow();
- m_SubVer.EnableWindow();
- m_EMail.EnableWindow();
- m_ProcTypeNumber.EnableWindow();
- m_PlugsInType.EnableWindow();
- m_Module.EnableWindow();
- m_ModuleName.SetWindowText((LPCTSTR)fname);
- m_ModuleName.EnableWindow();
- pk.comm = CMD_IS_SUPPORT;
- pk.result = ER_EMPTY;
- pk.annexdata.cmAnnData = CMD_LOAD_FROM_FILE;
- m_IRWPInterFace(&pk);
- if (pk.result == ER_SUCCESS)
- m_FunReadImage.SetCheck(1);
- else
- m_FunReadImage.SetCheck(0);
- m_FunReadImage.EnableWindow();
- pk.comm = CMD_IS_SUPPORT;
- pk.result = ER_EMPTY;
- pk.annexdata.cmAnnData = CMD_RESIZE;
- m_IRWPInterFace(&pk);
- if (pk.result == ER_SUCCESS)
- m_FunReReadImage.SetCheck(1);
- else
- m_FunReReadImage.SetCheck(0);
- m_FunReReadImage.EnableWindow();
- pk.comm = CMD_IS_SUPPORT;
- pk.result = ER_EMPTY;
- pk.annexdata.cmAnnData = CMD_SAVE_TO_FILE;
- m_IRWPInterFace(&pk);
- if (pk.result == ER_SUCCESS)
- m_FunSaveImage.SetCheck(1);
- else
- m_FunSaveImage.SetCheck(0);
- m_FunSaveImage.EnableWindow();
- m_DesFileName.EnableWindow();
- m_DesFileExist.SetCheck(1);
- m_DesFileExist.EnableWindow();
- m_ConvToIRW.EnableWindow();
- m_ConvToDLL.EnableWindow(FALSE);
- m_FillIRW.EnableWindow(FALSE);
- ::FreeLibrary(m_hDll);
- m_State = 1; // DLL to IRW
- }
- else if (!lstrcmp(ext, (LPCTSTR)".irw"))
- {
- TRY
- {
- CFile file((LPCTSTR)fn, CFile::modeReadWrite|CFile::typeBinary|CFile::shareExclusive);
- file.Seek(-(long)(sizeof(PLUGSIN)), CFile::end);
- file.Read((void*)&m_Info, sizeof(PLUGSIN));
- file.Close();
- }
- CATCH(CFileException, e)
- {
- MessageBox((LPCTSTR)"无法读取指定的IRW文件,请检查当前系统是否正常。",
- (LPCTSTR)"文件错误");
- return;
- }
- END_CATCH
- if ( (m_Info.IRWID[0] != 'I')||(m_Info.IRWID[1] != 'R')||
- (m_Info.IRWID[2] != 'W')||(m_Info.IRWID[3] != 'P') )
- {
- MessageBox((LPCTSTR)"指定的文件不是一个有效的IRW文件,请检查该文件是否被破坏。",
- (LPCTSTR)"文件错误");
- return;
- }
- m_FileType.SetWindowText((LPCTSTR)_T("ISee图像读写模块插件(IRW文件)"));
- soufn.Empty();
- soufn += drive;
- soufn += "\...\";
- soufn += fname;
- soufn += ext;
- desfn.Empty();
- desfn += drive;
- desfn += dir;
- desfn += fname;
- desfn += ".dll";
- m_SouFn = fd.GetPathName();
- m_SouFileName.SetWindowText((LPCTSTR)soufn);
- m_DesFileName.SetWindowText((LPCTSTR)desfn);
- m_HaHa.SetWindowText((LPCTSTR)m_Info.messages);
- m_HaHa.EnableWindow();
- m_Writer.SetWindowText((LPCTSTR)m_Info.author);
- m_Writer.EnableWindow();
- ::ZeroMemory((PVOID)ps, 256);
- PBYTE pps = (PBYTE)ps;
- for (int i=0;i<(int)m_Info.proctypenum;i++)
- {
- for (int j=0, k=0;j<4;j++)
- {
- if (m_Info.proctypestr[i*4+j] != 0)
- *pps++ = m_Info.proctypestr[i*4+j];
- else
- {
- if (k == 0)
- {
- *pps++ = (BYTE)',';
- k++;
- }
- }
- }
- if ((*(pps-1)) != ',')
- *pps++ = (BYTE)',';
- }
- ps[lstrlen((LPCTSTR)ps)-1] = 0; // 除去末尾的逗号
- m_ProcTypeStr.SetWindowText((LPCTSTR)ps);
- m_ProcTypeStr.EnableWindow();
- char pbuff[4];
- itoa((int)m_Info.proctypenum, (char*)pbuff, 10);
- m_ProcTypeNumber.SetWindowText((LPCTSTR)pbuff);
- m_ProcTypeNumber.EnableWindow();
- m_MajVer.SetCurSel(m_Info.version>>8);
- m_SubVer.SetCurSel(m_Info.version&0xff);
- m_MajVer.EnableWindow();
- m_SubVer.EnableWindow();
- m_EMail.SetWindowText((LPCTSTR)m_Info.EMail);
- m_EMail.EnableWindow();
- m_PlugsInType.SetCurSel(m_Info.attrib>>8);
- m_PlugsInType.EnableWindow();
- m_Module.SetCurSel(m_Info.attrib&0xff);
- m_Module.EnableWindow();
- m_ModuleName.SetWindowText((LPCTSTR)m_Info.modulename);
- m_ModuleName.EnableWindow();
- m_FunReadImage.SetCheck(m_Info.function&0x1);
- m_FunReadImage.EnableWindow();
- m_FunSaveImage.SetCheck((m_Info.function>>1)&0x1);
- m_FunSaveImage.EnableWindow();
- m_FunReReadImage.SetCheck((m_Info.function>>2)&0x1);
- m_FunReReadImage.EnableWindow();
- m_DesFileName.EnableWindow();
- m_DesFileExist.SetCheck(1);
- m_DesFileExist.EnableWindow();
- m_ConvToIRW.EnableWindow(FALSE);
- m_ConvToDLL.EnableWindow();
- m_FillIRW.EnableWindow();
- m_State = 2; // IRW to DLL or full
- }
- else
- {
- MessageBox((LPCTSTR)"应该选择以IRW或DLL为扩展名的文件。",
- (LPCTSTR)"文件选择错误");
- }
- }
- }
- int CIRWConvDlg::_GetProcTypeData(LPTSTR pSouStr, LPTSTR pDesStr)
- {
- BYTE c;
- PBYTE ps = (PBYTE)pSouStr;
- PBYTE pd = (PBYTE)pDesStr;
- int i = 0, soulen = 0, TypeNum = 0, TypeLen = 0, TypeFill = 0;
- soulen = ::lstrlen(pSouStr);
- if (soulen < 1)
- return 0; // 入口参数不合法
- _strupr((LPTSTR)ps);
- for (i=0;i<soulen;i++)
- {
- c = *ps++;
- if ((c == ',')||(c == ' '))
- continue;
- TypeNum++; TypeLen = 0;
- if (TypeNum > 8)
- {
- MessageBox((LPCTSTR)"单个模块不能支持多于8个类型文件的处理,请检查输入或修改代码。",
- (LPCTSTR)"参数错误");
- return 0;
- }
- do
- {
- *pd++ = c;
- TypeLen++;
- if (TypeLen > 4)
- {
- MessageBox((LPCTSTR)"单个文件类型描述不能超过4个字符,请检查输入数据。",
- (LPCTSTR)"参数错误");
- return 0;
- }
- c = *ps++;
- i++;
- }while((c != ',')&&(c != ' ')&&(i < soulen));
- TypeFill = 4 - TypeLen;
- ASSERT(TypeFill >= 0);
- while(TypeFill--) *pd++ = 0;
- }
- return TypeNum;
- }
- void CIRWConvDlg::OnConvToDll()
- {
- ASSERT(m_State == 2);
-
- BYTE path[MAX_PATH];
- HANDLE hSou = ::CreateFile((LPCTSTR)m_SouFn, GENERIC_READ,
- FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hSou == INVALID_HANDLE_VALUE)
- {
- MessageBox((LPCTSTR)"指定的IRW文件打不开,请检查是否有程序正在使用该文件(如果有请关闭这个程序)。",
- (LPCTSTR)"系统错误");
- return;
- }
- // 获取目标文件名
- ::ZeroMemory((PVOID)path, MAX_PATH);
- m_DesFileName.GetWindowText((LPTSTR)path, MAX_PATH);
- DWORD dwCreateAttr;
- if (m_DesFileExist.GetCheck() == 0)
- dwCreateAttr = CREATE_ALWAYS;
- else
- dwCreateAttr = CREATE_NEW;
- HANDLE hDes = ::CreateFile((LPCTSTR)path, GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ, NULL, dwCreateAttr, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hDes == INVALID_HANDLE_VALUE)
- {
- ::CloseHandle(hSou);
- MessageBox((LPCTSTR)"无法还原DLL文件(或者该文件已经存在),请检查。",
- (LPCTSTR)"系统错误");
- return;
- }
- int result = _CopyFileToDLL(hDes, hSou);
- ::CloseHandle(hSou);
- ::CloseHandle(hDes);
- if (result == 0)
- {
- MessageBox((LPCTSTR)"操作成功!已还原出DLL文件。",
- (LPCTSTR)"操作成功");
- }
- else if (result == -1)
- {
- MessageBox((LPCTSTR)"内存不足,无法完成操作!请关闭一些软件再试。",
- (LPCTSTR)"系统错误");
- }
- else if (result == -2)
- {
- MessageBox((LPCTSTR)"读、写文件时出错,请检查系统现在是否稳定!",
- (LPCTSTR)"系统错误");
- }
- else
- ASSERT(FALSE);
- return;
- }
- void CIRWConvDlg::OnConvToIrw()
- {
- ASSERT(m_State == 1);
- BYTE path[MAX_PATH];
- BYTE ps[256];
-
- ::ZeroMemory((PVOID)&m_Info, sizeof(PLUGSIN));
- ::memmove((void*)m_Info.IRWID, (const void*)"IRWP", 4);
- m_Info.attrib = (m_PlugsInType.GetCurSel() == 0) ? 0:1;
- m_Info.attrib <<= 8; // 高字节表示插件类型(内置0或外置1)
- m_Info.attrib |= (m_Module.GetCurSel() == 0) ? 0:1;
- // 低字节表示插件是DEBUG版的(1)还是发布版的(0)
- m_Info.version = m_MajVer.GetCurSel();
- m_Info.version <<= 8; // 高字节是主版本号(不大于9)
- m_Info.version |= m_SubVer.GetCurSel();
- ::ZeroMemory((PVOID)ps, 256);
- m_ProcTypeStr.GetWindowText((LPTSTR)ps, 256);
- m_Info.proctypenum = _GetProcTypeData((LPTSTR)ps, (LPTSTR)(m_Info.proctypestr));
- if (!m_Info.proctypenum)
- {
- MessageBox((LPCTSTR)"ISee的图像读写插件必需能处理一种或一种以上的文件类型,请检查输入的参数是否正确。",
- (LPCTSTR)"参数错误");
- return;
- }
- ::ZeroMemory((PVOID)ps, 256);
- m_Writer.GetWindowText((LPTSTR)ps, 256);
- if (::lstrlen((LPCTSTR)ps) > 15)
- {
- MessageBox((LPCTSTR)"作者的名单太长了,应适当减小(小于16个英文字符的长度)。",
- (LPCTSTR)"参数错误");
- return;
- }
- ::CopyMemory((PVOID)m_Info.author, (PVOID)ps, 16);
- ::ZeroMemory((PVOID)ps, 256);
- m_EMail.GetWindowText((LPTSTR)ps, 256);
- if (::lstrlen((LPCTSTR)ps) > 31)
- {
- MessageBox((LPCTSTR)"EMail地址太长了,是否可适当减小(应小于32个英文字符的长度)。",
- (LPCTSTR)"参数错误");
- return;
- }
- ::CopyMemory((PVOID)m_Info.EMail, (PVOID)ps, 32);
- ::ZeroMemory((PVOID)ps, 256);
- m_HaHa.GetWindowText((LPTSTR)ps, 256);
- if (::lstrlen((LPCTSTR)ps) > 143)
- {
- MessageBox((LPCTSTR)"留言太多了,是否可适当缩减(应小于72个汉字的长度)。",
- (LPCTSTR)"参数错误");
- return;
- }
- ::CopyMemory((PVOID)m_Info.messages, (PVOID)ps, 144);
- // 内部支持功能
- m_Info.function = m_FunReReadImage.GetState()&0x1;
- m_Info.function <<= 1;
- m_Info.function |= m_FunSaveImage.GetState()&0x1;
- m_Info.function <<= 1;
- m_Info.function |= m_FunReadImage.GetState()&0x1;
- // 模块名字
- ::ZeroMemory((PVOID)ps, 256);
- m_ModuleName.GetWindowText((LPTSTR)ps, 256);
- if (::lstrlen((LPCTSTR)ps) > 15)
- {
- MessageBox((LPCTSTR)"模块名太长了,是否可适当缩减(应小于16个字节)。",
- (LPCTSTR)"参数错误");
- return;
- }
- ::CopyMemory((PVOID)m_Info.modulename, (PVOID)ps, 16);
- HANDLE hSou = ::CreateFile((LPCTSTR)m_SouFn, GENERIC_READ,
- FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hSou == INVALID_HANDLE_VALUE)
- {
- MessageBox((LPCTSTR)"指定的DLL文件打不开,请检查是否有程序正在使用该文件(如果有请关闭这个程序)。",
- (LPCTSTR)"系统错误");
- return;
- }
- // 获取目标文件名
- ::ZeroMemory((PVOID)path, MAX_PATH);
- m_DesFileName.GetWindowText((LPTSTR)path, MAX_PATH);
- DWORD dwCreateAttr;
- if (m_DesFileExist.GetCheck() == 0)
- dwCreateAttr = CREATE_ALWAYS;
- else
- dwCreateAttr = CREATE_NEW;
- HANDLE hDes = ::CreateFile((LPCTSTR)path, GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ, NULL, dwCreateAttr, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hDes == INVALID_HANDLE_VALUE)
- {
- ::CloseHandle(hSou);
- MessageBox((LPCTSTR)"无法创建IRW文件(或者该文件已经存在),请检查。",
- (LPCTSTR)"系统错误");
- return;
- }
- int result = _CopyFileToIRW(hDes, hSou);
- ::CloseHandle(hSou);
- ::CloseHandle(hDes);
- if (result == 0)
- {
- MessageBox((LPCTSTR)"操作成功!IRW文件已建立。",
- (LPCTSTR)"操作成功");
- }
- else if (result == -1)
- {
- MessageBox((LPCTSTR)"内存不足,无法完成操作!请关闭一些软件再试。",
- (LPCTSTR)"系统错误");
- }
- else if (result == -2)
- {
- MessageBox((LPCTSTR)"读、写文件时出错,请检查系统现在是否稳定!",
- (LPCTSTR)"系统错误");
- }
- else
- ASSERT(FALSE);
- return;
- }
- void CIRWConvDlg::OnFillIrw()
- {
- ASSERT(m_State == 2);
- BYTE ps[256];
-
- ::ZeroMemory((PVOID)&m_Info, sizeof(PLUGSIN));
- ::memmove((void*)m_Info.IRWID, (const void*)"IRWP", 4);
- m_Info.attrib = (m_PlugsInType.GetCurSel() == 0) ? 0:1;
- m_Info.attrib <<= 8; // 高字节表示插件类型(内置0或外置1)
- m_Info.attrib |= (m_Module.GetCurSel() == 0) ? 0:1;
- // 低字节表示插件是DEBUG版的(1)还是发布版的(0)
- m_Info.version = m_MajVer.GetCurSel();
- m_Info.version <<= 8; // 高字节是主版本号(不大于9)
- m_Info.version |= m_SubVer.GetCurSel();
- ::ZeroMemory((PVOID)ps, 256);
- m_ProcTypeStr.GetWindowText((LPTSTR)ps, 256);
- m_Info.proctypenum = _GetProcTypeData((LPTSTR)ps, (LPTSTR)(m_Info.proctypestr));
- if (!m_Info.proctypenum)
- {
- MessageBox((LPCTSTR)"ISee的图像读写插件必需能处理一种或一种以上的文件类型,请检查输入的参数是否正确。",
- (LPCTSTR)"参数错误");
- return;
- }
- ::ZeroMemory((PVOID)ps, 256);
- m_Writer.GetWindowText((LPTSTR)ps, 256);
- if (::lstrlen((LPCTSTR)ps) > 15)
- {
- MessageBox((LPCTSTR)"作者的名单太长了,应适当减小(小于16个英文字符的长度)。",
- (LPCTSTR)"参数错误");
- return;
- }
- ::CopyMemory((PVOID)m_Info.author, (PVOID)ps, 16);
- ::ZeroMemory((PVOID)ps, 256);
- m_EMail.GetWindowText((LPTSTR)ps, 256);
- if (::lstrlen((LPCTSTR)ps) > 31)
- {
- MessageBox((LPCTSTR)"EMail地址太长了,是否可适当减小(应小于32个英文字符的长度)。",
- (LPCTSTR)"参数错误");
- return;
- }
- ::CopyMemory((PVOID)m_Info.EMail, (PVOID)ps, 32);
- ::ZeroMemory((PVOID)ps, 256);
- m_HaHa.GetWindowText((LPTSTR)ps, 256);
- if (::lstrlen((LPCTSTR)ps) > 143)
- {
- MessageBox((LPCTSTR)"留言太多了,是否可适当缩减(应小于72个汉字的长度)。",
- (LPCTSTR)"参数错误");
- return;
- }
- ::CopyMemory((PVOID)m_Info.messages, (PVOID)ps, 144);
- // 内部支持功能
- m_Info.function = m_FunReReadImage.GetState()&0x1;
- m_Info.function <<= 1;
- m_Info.function |= m_FunSaveImage.GetState()&0x1;
- m_Info.function <<= 1;
- m_Info.function |= m_FunReadImage.GetState()&0x1;
- // 模块名字
- ::ZeroMemory((PVOID)ps, 256);
- m_ModuleName.GetWindowText((LPTSTR)ps, 256);
- if (::lstrlen((LPCTSTR)ps) > 15)
- {
- MessageBox((LPCTSTR)"模块名太长了,是否可适当缩减(应小于16个字节)。",
- (LPCTSTR)"参数错误");
- return;
- }
- ::CopyMemory((PVOID)m_Info.modulename, (PVOID)ps, 16);
- HANDLE hDes = ::CreateFile((LPCTSTR)m_SouFn, GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hDes == INVALID_HANDLE_VALUE)
- {
- MessageBox((LPCTSTR)"无法创建IRW文件(或者该文件已经存在),请检查。",
- (LPCTSTR)"系统错误");
- return;
- }
- int result = _FillToIrw(hDes);
- ::CloseHandle(hDes);
- if (result == 0)
- {
- MessageBox((LPCTSTR)"操作成功!IRW文件中的附加信息已刷新。",
- (LPCTSTR)"操作成功");
- }
- else if (result == -2)
- {
- MessageBox((LPCTSTR)"读、写文件时出错,请检查系统现在是否稳定!",
- (LPCTSTR)"系统错误");
- }
- else
- ASSERT(FALSE);
- return;
- }
- int CIRWConvDlg::_FillToIrw(HANDLE hDes)
- {
- ASSERT(hDes);
- CFile desfile((int)hDes);
- TRY
- {
- desfile.Seek(-(long)(sizeof(PLUGSIN)), CFile::end);
- desfile.Write((const void*)&m_Info, sizeof(PLUGSIN));
- }
- CATCH(CFileException, e)
- {
- return -2; // 在读写文件的过程中发生错误
- }
- END_CATCH
- return 0;
- }
- int CIRWConvDlg::_CopyFileToIRW(HANDLE hDes, HANDLE hSou)
- {
- ASSERT(hDes);
- ASSERT(hSou);
- CFile soufile((int)hSou);
- CFile desfile((int)hDes);
- DWORD dwFileLen = soufile.GetLength();
- PBYTE pBuff = (PBYTE)::GlobalAlloc(GPTR, dwFileLen);
- if (!pBuff)
- return -1; // 内存不足
- TRY
- {
- soufile.SeekToBegin();
- desfile.SeekToBegin();
- soufile.ReadHuge((void*)pBuff, dwFileLen);
- desfile.WriteHuge((const void*)pBuff, dwFileLen);
- desfile.Write((const void*)&m_Info, sizeof(PLUGSIN));
- }
- CATCH(CFileException, e)
- {
- ::GlobalFree(pBuff);
- return -2; // 在读写文件的过程中发生错误
- }
- END_CATCH
- ::GlobalFree(pBuff);
- return 0; // OK
- }
- int CIRWConvDlg::_CopyFileToDLL(HANDLE hDes, HANDLE hSou)
- {
- ASSERT(hDes);
- ASSERT(hSou);
- CFile soufile((int)hSou); // IRW file
- CFile desfile((int)hDes); // DLL file
- DWORD dwFileLen = soufile.GetLength()-sizeof(PLUGSIN);
- PBYTE pBuff = (PBYTE)::GlobalAlloc(GPTR, dwFileLen);
- if (!pBuff)
- return -1; // 内存不足
- TRY
- {
- soufile.SeekToBegin();
- desfile.SeekToBegin();
- soufile.ReadHuge((void*)pBuff, dwFileLen);
- desfile.WriteHuge((const void*)pBuff, dwFileLen);
- }
- CATCH(CFileException, e)
- {
- ::GlobalFree(pBuff);
- return -2; // 在读写文件的过程中发生错误
- }
- END_CATCH
- ::GlobalFree(pBuff);
- return 0; // OK
- }