Справочник функций

Ваш аккаунт

Войти через: 
Забыли пароль?
Регистрация
Информацию о новых материалах можно получать и без регистрации:

Почтовая рассылка

Подписчиков: -1
Последний выпуск: 19.06.2015

Ресурсы!

404
06 января 2004 года
GooD
108 / / 04.12.2003
Народ хелп!
Есть функции:BeginUpdateResource,UpdateResource, EndUpdateResource.Если ктонибудь знает как ими пользоватся напишите!


---------
Зарание огромное Спасибо!!!
1.9K
10 января 2004 года
AviDen
91 / / 26.12.2003
Цитата:
Originally posted by GooD
Народ хелп!
Есть функции:BeginUpdateResource,UpdateResource, EndUpdateResource.Если ктонибудь знает как ими пользоватся напишите!


---------
Зарание огромное Спасибо!!!



Using Resources

--------------------------------------------------------------------------------

This section contains code snippets for the following tasks:

Updating Resources
Creating a Resource List
Updating Resources
The following example copies a dialog box resource from one executable file, Hand.exe, to another, Foot.exe, by following these steps:

Use the LoadLibrary function to load the executable file Hand.exe.
Use the FindResource and LoadResource functions to locate and load the dialog box resource.
Use the LockResource function to retrieve a pointer to the dialog box resource data.
Use the BeginUpdateResource function to open an update handle to Foot.exe.
Use the UpdateResource function to copy the dialog box resource from Hand.exe to Foot.exe.
Use the EndUpdateResource function to complete the update.
The following code implements these steps.

Security Alert Using LoadLibrary incorrectly can compromise the security of your application by loading the wrong DLL. Refer to the LoadLibrary documentation for information on how to correctly load DLLs with different versions of Microsoft® Windows®.


Код:
HRSRC hResLoad;     // handle to loaded resource
HANDLE hExe;        // handle to existing .EXE file
HRSRC hRes;         // handle/ptr. to res. info. in hExe
HANDLE hUpdateRes;  // update resource handle
char *lpResLock;    // pointer to resource data
BOOL result;
// Load the .EXE file that contains the dialog box you want to copy.
hExe = LoadLibrary("hand.exe");
if (hExe == NULL)
{
    ErrorHandler("Could not load exe.");
}
 
// Locate the dialog box resource in the .EXE file.
hRes = FindResource(hExe, "AboutBox", RT_DIALOG);
if (hRes == NULL)
{
    ErrorHandler("Could not locate dialog box.");
}
 
// Load the dialog box into global memory.
hResLoad = LoadResource(hExe, hRes);
if (hResLoad == NULL)
{
    ErrorHandler("Could not load dialog box.");
}
 
// Lock the dialog box into global memory.
lpResLock = LockResource(hResLoad);
if (lpResLock == NULL)
{
    ErrorHandler("Could not lock dialog box.");
}
 
// Open the file to which you want to add the dialog box resource.
hUpdateRes = BeginUpdateResource("foot.exe", FALSE);
if (hUpdateRes == NULL)
{
    ErrorHandler("Could not open file for writing.");
}
 
// Add the dialog box resource to the update list.
result = UpdateResource(hUpdateRes,       // update resource handle
     RT_DIALOG,                   // change dialog box resource
     "AboutBox",                  // dialog box name
     MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),  // neutral language
     lpResLock,                   // ptr to resource info
     SizeofResource(hExe, hRes)); // size of resource info.
if (result == FALSE)
{
    ErrorHandler("Could not add resource.");
}
 
// Write changes to FOOT.EXE and then close it.
if (!EndUpdateResource(hUpdateRes, FALSE))
{
    ErrorHandler("Could not write changes to file.");
}
 
// Clean up.
if (!FreeLibrary(hExe))
{
    ErrorHandler("Could not free executable.");
}
1.9K
10 января 2004 года
AviDen
91 / / 26.12.2003
Цитата:
Originally posted by GooD
Народ хелп!
Есть функции:BeginUpdateResource,UpdateResource, EndUpdateResource.Если ктонибудь знает как ими пользоватся напишите!


---------
Зарание огромное Спасибо!!!




И второй экземпл (оба из MSDN, там же и все подробности - лучшей доки не сыскать).


Creating a Resource List
The following example creates a list of every resource in the Hand.exe file. The list is written to the Resinfo.txt file.

The code demonstrates how to load the executable file, create a file in which to write resource information, and call the EnumResourceTypes function to send each resource type found in the module to the application-defined callback function EnumTypesFunc. See EnumResTypeProc for information on callback functions of this type. This callback function uses the EnumResourceNames function to pass the name of every resource within the specified type to another application-defined callback function, EnumNamesFunc. See EnumResNameProc for information on callback functions of this type. EnumNamesFunc uses the EnumResourceLanguages function to pass the language of every resource of the specified type and name to a third callback function, EnumLangsFunc. See EnumResLangProc for information on callback functions of this type. EnumLangsFunc writes information about the resource of the specified type, name, and language to the Resinfo.txt file.

Note that the lpszType in EnumResTypeProc is either a resource identifier (ID) or a pointer to a string (containing a resource ID or type name); lpszType and lpszName in EnumResNameProc are similar. To use an enumerated resource, take the resource name or ID and call the appropriate function. For example, to load a string resource (RT_STRING), if lpszName in EnumResNameProc gives the resource ID (either directly or in a string that starts with the pound sign (#)), call LoadString. Otherwise, lpszName points to a string containing the resource name, so do the following:

call FindResource or FindResourceEx with the resource name to get the resource handle;
call LoadResource with the resource handle to get the global handle;
call LockResource with the global handle to get a pointer to the resource data.
The Updating Resources code follows a similar pattern for a dialog box resource.

Security Alert Using LoadLibrary incorrectly can compromise the security of your application by loading the wrong DLL. Refer to the LoadLibrary documentation for information on how to correctly load DLLs with different versions of Windows.

Код:
char szBuffer[80]; // print buffer for EnumResourceTypes
DWORD cbWritten;   // number of bytes written to res. info. file
size_t cbString;      // length of string in sprintf
HRESULT hResult;
 
// Declare callback functions.
BOOL EnumTypesFunc(
    HANDLE hModule,
    LPTSTR lpType,
    LONG lParam);
 
BOOL EnumNamesFunc(
    HANDLE hModule,
    LPCTSTR lpType,
    LPTSTR lpName,
    LONG lParam);
 
BOOL EnumLangsFunc(
    HANDLE hModule,
    LPCTSTR lpType,
    LPCTSTR lpName,
    WORD wLang,
    LONG lParam);
 
// Load the .EXE whose resources you want to list.
hExe = LoadLibrary("hand.exe");
if (hExe == NULL)
{
// Add code to fail as securely as possible.
    return;
}
 
// 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,      // default security
    CREATE_ALWAYS,                     // create flags
    FILE_ATTRIBUTE_NORMAL,             // file attributes
    (HANDLE) NULL);                    // no template
if (hFile == INVALID_HANDLE_VALUE) {
    ErrorHandler("Could not open file.");
}
 
// Find all of the loaded file's resources.
hResult = StringCchPrintf(szBuffer, 80/sizeof(TCHAR),  
// cbString = sprintf(szBuffer,
    "The file contains the following resources:\n\n");
if (FAILED(hResult))
    {
    // Add code to fail as securely as possible.
    return;
    }
hResult = StringCchLength(szBuffer, 80/sizeof(TCHAR), cbString);
if (FAILED(hResult))
    {
    // Add code to fail as securely as possible.
    return;
    }
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 EnumTypesFunc(
    HANDLE hModule,   // module handle
    LPTSTR lpType,    // address of resource type
    LONG lParam)      // extra parameter, could be
                      // used for error checking
{
    size_t cbString;
    HRESULT hResult;
     
    // 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)
    {
        hResult = StringCchPrintf(szBuffer, 80/sizeof(TCHAR), "Type: %s\n", lpType);
        if (FAILED(hResult))
        {
        // Add code to fail as securely as possible.
            return;
        }
    // cbString = sprintf(szBuffer, "Type: %s\n", lpType);
    }
    else
    {
        hResult = StringCchPrintf(szBuffer, 80/sizeof(TCHAR), "Type: %u\n", (USHORT)lpType);
        if (FAILED(hResult))
        {
        // Add code to fail as securely as possible.
            return;
        }
//        cbString = sprintf(szBuffer, "Type: %u\n", (USHORT)lpType);
    }
 hResult = StringCchLength(szBuffer, 80/sizeof(TCHAR), cbString);
    if (FAILED(hResult))
        {
        // Add code to fail as securely as possible.
            return;
        }
    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 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
{
    size_t cbString;
    HRESULT hResult;
   
     // 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)
    {
        hResult = StringCchPrintf(szBuffer, 80/sizeof(TCHAR), "\tName: %s\n", lpName);
        if (FAILED(hResult))
        {
        // Add code to fail as securely as possible.
            return;
        }
//        cbString = sprintf(szBuffer, "\tName: %s\n", lpName);
    }
    else
    {
        hResult = StringCchPrintf(szBuffer, 80/sizeof(TCHAR), "\tName: %u\n", (USHORT)lpName);
        if (FAILED(hResult))
        {
        // Add code to fail as securely as possible.
            return;
        }
//        cbString = sprintf(szBuffer, "\tName: %u\n",
            (USHORT)lpName);
    }
    hResult = StringCchLength(szBuffer, 80/sizeof(TCHAR), cbString);
    if (FAILED(hResult))
        {
        // Add code to fail as securely as possible.
            return;
        }
 
    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 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];
    size_t cbString = 0;
    HRESULT hResult;
 
    hResInfo = FindResourceEx(hModule, lpType, lpName, wLang);
    // Write the resource language to the resource information file.
    hResult = StringCchPrintf(szBuffer, 80/sizeof(TCHAR), "\t\tLanguage: %u\n", (USHORT) wLang);
        if (FAILED(hResult))
        {
        // Add code to fail as securely as possible.
            return;
        }
        hResult = StringCchLength(szBuffer, 80/sizeof(TCHAR), cbString);
    if (FAILED(hResult))
        {
        // Add code to fail as securely as possible.
            return;
        }
//    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;
}
Реклама на сайте | Обмен ссылками | Ссылки | Экспорт (RSS) | Контакты
Добавить статью | Добавить исходник | Добавить хостинг-провайдера | Добавить сайт в каталог