我想创建一些中英文资源,想用FindResourceEx来导入,但是总是不成功,
不知道是什么原因,原代码如下,当然,资源的ID是存在的,即使我想导入中文的资源也不行
但是用FindResource()却可以,为什么呢?谢谢
HINSTANCE hInstance= ((CSNMPTESTApp*)AfxGetApp())->m_hInstance;//
if (hDll)
{
CDlgTest dlg;
WORD w = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
HRSRC hRsrc = ::FindResourceEx(hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), RT_DIALOG, w);
if (hRsrc)
{
HGLOBAL hGlobal = ::LoadResource(hDll, hRsrc);
dlg.InitModalIndirect(hGlobal);
dlg.DoModal();
}
}

解决方案 »

  1.   

    HRSRC FindResourceEx(          HMODULE hModule,
        LPCTSTR lpType,
        LPCTSTR lpName,
        WORD wLanguage
    );HRSRC FindResource(          HMODULE hModule,
        LPCTSTR lpName,
        LPCTSTR lpType
    );=========================.See???
    lpName  lpType  顺序:)So
    ::FindResourceEx(hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), RT_DIALOG, w);
    应该是
    ::FindResourceEx(hInstance, RT_DIALOG,,MAKEINTRESOURCE(IDD_ABOUTBOX),  w);
      

  2.   

    给我全部的分数,我给你通用的代码
    BOOL CRcResource::UnpackResource2(LPCTSTR file_path, DWORD source_id, LPCTSTR source_type)
    {
    CString strFullPath, strFilePath, strFileName;
    strFullPath.Format("%s", file_path);
    int index = strFullPath.ReverseFind('\\');
    strFilePath = strFullPath.Left(index);
    strFileName = strFullPath.Mid(index+1); char szError[1024] = {0};
    // Get the resource handle.
    HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(source_id), source_type);
    if (hInst == NULL)
    {
    m_strErrorMessage.Format("程序读取失败!可能文件已损坏,请重新获取程序![" + strFileName + "]");
    return FALSE;
    }
    // Find, Load and Lock the resource containing file(s) data.
    HRSRC hResLoad = FindResource(hInst, MAKEINTRESOURCE(source_id), source_type);
    if (hResLoad == NULL)
    {
    SetErrorMessage(GetLastError(), strFileName);
    return FALSE;
    }
    // We should have properly loaded the resource.
    HGLOBAL hResData = LoadResource(hInst, hResLoad);
    if (hResData == NULL)
    {
    SetErrorMessage(GetLastError(), strFileName);
    return FALSE;
    }
    // We should have properly loaded the resource.
    LPCSTR data = (LPCSTR)LockResource(hResData);
    if (data == NULL)
    {
    m_strErrorMessage.Format("无法获得映像文件中指定的资源数据![" + strFileName + "]");
    return FALSE;
    }
    DWORD dwResSize = SizeofResource(hInst, hResLoad); // Copy the resource file.
    try
    {
    CFile f;
    CFileException ex;
    if (!f.Open(strFullPath, CFile::modeCreate|CFile::modeReadWrite, &ex))
    {
    // ex.ReportError();
    if (ex.GetErrorMessage(szError, sizeof(szError)))
    m_strErrorMessage.Format("%s[%s]", szError, strFileName);
    else
    m_strErrorMessage.Format("解压文件时出错![" + strFileName + "]");
    return FALSE;
    }
    f.WriteHuge(hResData, dwResSize);
    f.Close();
    }
    catch (CFileException ex)
    {
    FreeResource(hResData);
    if (ex.GetErrorMessage(szError, sizeof(szError)))
    m_strErrorMessage.Format("%s[%s]", szError, strFileName);
    else
    m_strErrorMessage.Format("解压文件时出错![" + strFileName + "]");
    return FALSE;
    }
    catch (CException ex)
    {
    FreeResource(hResData);
    if (ex.GetErrorMessage(szError, sizeof(szError)))
    m_strErrorMessage.Format("%s[%s]", szError, strFileName);
    else
    m_strErrorMessage.Format("解压文件时出错![" + strFileName + "]");
    return FALSE;
    }
    catch(...)
    {
    FreeResource(hResData);
    m_strErrorMessage.Format("解压文件时出错![" + strFileName + "]");
    return FALSE;
    } // Perform cleanup
    FreeResource(hResData); return TRUE;
    }调用:
    CRcResource pack; if (!pack.UpdateFileResource2(m_strSourceFile, m_strReleaseFile, 135, "IDR_ZIP"))