这是对话框按钮的代码,用于在hand.exe中找出它的资源,并输入到resinfo.txt中。
void CUpdaterDlg::OnButton2() 
{
// TODO: Add your control notification handler code here
hExe = LoadLibrary("hand.exe"); 
if (hExe == NULL) 

    MessageBox("Could not load .EXE."); 

 
// Create a file to contain the resource info. 
hFile = CreateFile("resinfo.txt",      // name of file 
    GENERIC_READ | GENERIC_WRITE,      // access mode 
    0,                                 // share mode 
    (LPSECURITY_ATTRIBUTES) NULL,      // no security 
    CREATE_ALWAYS,                     // create flags 
    FILE_ATTRIBUTE_NORMAL,             // file attributes 
    (HANDLE) NULL);                    // no template 
if (hFile == INVALID_HANDLE_VALUE) { 
    MessageBox("Could not open file."); 

 
// Find all of the loaded file's resources. 
cbString = sprintf(szBuffer, 
    "The file contains the following resources:\n\n"); 
WriteFile(hFile,           // file to hold resource info. 
    szBuffer,              // what to write to the file 
    (DWORD) cbString,      // number of bytes in szBuffer 
    &cbWritten,            // number of bytes written 
    NULL);                 // no overlapped I/O 
 
EnumResourceTypes(hExe,              // module handle 
    (ENUMRESTYPEPROC)EnumTypesFunc,  // callback function 
    0);                              // extra parameter 
// Unload the executable file whose resources were 
// enumerated and close the file created to contain 
// the resource information. 
FreeLibrary(hExe); 
CloseHandle(hFile); }
以下是回调函数:
//    FUNCTION: EnumTypesFunc(HANDLE, LPSTR, LONG) 
// 
//    PURPOSE:  Resource type callback 
BOOL CUpdaterDlg::EnumTypesFunc( 
    HANDLE hModule,   // module handle 
    LPTSTR lpType,    // address of resource type 
    LONG lParam)      // extra parameter, could be 
                      // used for error checking 

    int cbString; 
    // Write the resource type to a resource information file. 
    // The type may be a string or an unsigned decimal 
    // integer, so test before printing. 
    if ((ULONG)lpType & 0xFFFF0000) 
    { 
        cbString = sprintf(szBuffer, "Type: %s\n", lpType); 
    } 
    else 
    { 
        cbString = sprintf(szBuffer, "Type: %u\n", (USHORT)lpType); 
    } 
 
    WriteFile(hFile, szBuffer, (DWORD) cbString, 
        &cbWritten, NULL); 
    // Find the names of all resources of type lpType. 
    EnumResourceNames(hModule, 
        lpType, 
        (ENUMRESNAMEPROC)EnumNamesFunc, 
        0); 
 
    return TRUE; 

 
//    FUNCTION: EnumNamesFunc(HANDLE, LPSTR, LPSTR, LONG) 
// 
//    PURPOSE:  Resource name callback 
BOOL CUpdaterDlg::EnumNamesFunc( 
    HANDLE hModule,   // module handle 
    LPCTSTR lpType,   // address of resource type 
    LPTSTR lpName,    // address of resource name 
    LONG lParam)      // extra parameter, could be 
                      // used for error checking 

    int cbString; 
     // Write the resource name to a resource information file. 
     // The name may be a string or an unsigned decimal 
     // integer, so test before printing. 
    if ((ULONG)lpName & 0xFFFF0000) 
    { 
        cbString = sprintf(szBuffer, "\tName: %s\n", lpName); 
    } 
    else 
    { 
        cbString = sprintf(szBuffer, "\tName: %u\n", 
            (USHORT)lpName); 
    } 
 
    WriteFile(hFile, szBuffer, (DWORD) cbString, 
        &cbWritten, NULL); 
     // Find the languages of all resources of type 
     // lpType and name lpName. 
    EnumResourceLanguages(hModule, 
        lpType, 
        lpName, 
        (ENUMRESLANGPROC)EnumLangsFunc, 
        0); 
 
    return TRUE; 

 
//    FUNCTION: EnumLangsFunc(HANDLE, LPSTR, LPSTR, WORD, LONG) 
// 
//    PURPOSE:  Resource language callback 
BOOL CUpdaterDlg::EnumLangsFunc( 
    HANDLE hModule,  // module handle 
    LPCTSTR lpType,  // address of resource type 
    LPCTSTR lpName,  // address of resource name 
    WORD wLang,      // resource language 
    LONG lParam)     // extra parameter, could be 
                     // used for error checking 

    HANDLE hResInfo; 
    char szBuffer[80]; 
    int cbString = 0; 
 
    hResInfo = FindResourceEx(hModule, lpType, lpName, wLang); 
    // Write the resource language to the resource information file. 
    cbString = sprintf(szBuffer, "\t\tLanguage: %u\n", (USHORT)wLang); 
    WriteFile(hFile, szBuffer, (DWORD) cbString, 
        &cbWritten, NULL); 
    // Write the resource handle and size to buffer. 
    cbString = sprintf(szBuffer, 
        "\t\thResInfo == %lx,  Size == %lu\n\n", 
        hResInfo, 
        SizeofResource(hModule, hResInfo)); 
    WriteFile(hFile, szBuffer, (DWORD) cbString, 
        &cbWritten, NULL); 
    return TRUE; 

以下是变量声明:
BOOL CALLBACK EnumTypesFunc( 
    HANDLE hModule, 
    LPTSTR lpType, 
    LONG lParam); 
 
BOOL CALLBACK EnumNamesFunc( 
    HANDLE hModule, 
    LPCTSTR lpType, 
    LPTSTR lpName, 
    LONG lParam); 
 
BOOL CALLBACK EnumLangsFunc( 
    HANDLE hModule, 
    LPCTSTR lpType, 
    LPCTSTR lpName, 
    WORD wLang, 
    LONG lParam); 
// Dialog Data
//{{AFX_DATA(CUpdaterDlg)
enum { IDD = IDD_UPDATER_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CUpdaterDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected:
HICON m_hIcon;
HGLOBAL hResLoad;     // handle to loaded resource 
HMODULE hExe;        // handle to existing .EXE file 
HRSRC hRes;         // handle/ptr. to res. info. in hExe 
HANDLE hUpdateRes,hFile;  // update resource handle 
HGLOBAL lpResLock;    // pointer to resource data 
BOOL result; 
char szBuffer[80]; // print buffer for EnumResourceTypes 
DWORD cbWritten;   // number of bytes written to res. info. file 
int cbString;      // length of string in sprintf 其实这些都是我从MSDN里的一篇文章中抄出来的,结果编译器说
: error C2440: 'type cast' : cannot convert from '' to 'int (__stdcall *)(struct HINSTANCE__ *,char *,long)'
就是EnumResourceTypes(hExe,              // module handle 
    (ENUMRESTYPEPROC)EnumTypesFunc,  // callback function 
    0);       这里,还有其他几处error跟这个很类似,不再写出来了。请高手调试我的代码,谢谢。

解决方案 »

  1.   

    将所有callback函数声明为static?
      

  2.   

    to Hendy_So
    static那些callback也不行,编译错误更多
      

  3.   

    搁在外面,别放在类中BOOL EnumTypesFunc( 
        HANDLE hModule,   // module handle 
        LPTSTR lpType,    // address of resource type 
        LONG lParam)      // extra parameter, could be 
                          // used for error checking 
    {
      

  4.   

    to vcmute
    你说的对,应该把声明和实现都放在类外边
    我也这么做了
    但是又出了新的错误:
    error LNK2001: unresolved external symbol "int __cdecl EnumNamesFunc(void *,char const *,char *,long)" (?EnumNamesFunc@@YAHPAXPBDPADJ@Z)
    意思是“找不到了“怎么办?