0
0

I ‘m trying to initialize fmod in my project in the DllMain function that is dynamically loaded in runtime from my application. Below is the initialization code of fmod:

[code:1maw4gol]
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:

        //-- TODO: Initialize FMOD library
        FMOD_RESULT result;
        FMOD::System *system;

        result = FMOD::System_Create(&system);
        if (result != FMOD_OK)
        {
            PRINT("FMOD error");
        }

        result = system->init(32, FMOD_INIT_NORMAL, 0);
        if (result != FMOD_OK)
        {
            PRINT("FMOD error");
                            //printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
        }
        break;

    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
        break;

    case DLL_PROCESS_DETACH:
        //-- TODO: CleanUp FMOD library
        break;
}
return TRUE;

}
[/code:1maw4gol]

However System::init() does not return when called! Program execution freezes in the call (possible locked in a loop?). Any ideas what is the problem? This only happens when I link to fmodex_vc.lib. When linking to fmodexp_vc.lib I dont have that problem, but I get an error 57 that a requested dsp codec is missing and I have no idea what codec is missing.

Thanks in advance,
themis[/code]

  • You must to post comments
0
0

take a look at what MSDN says about DllMain:

[quote:rbis19f7]

Warning There are serious limits on what you can do in a DLL entry point. To provide more complex initialization, create an initialization routine for the DLL. You can require applications to call the initialization routine before calling any other routines in the DLL. Alternatively, the initialization routine can create a file with an ACL that restricts access, and each routine in the DLL would call the initialization routine if the file does not exist.

The entry-point function should perform only simple initialization or termination tasks. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order. This can result in a DLL being used before the system has executed its initialization code. Similarly, the entry-point function must not call the FreeLibrary function (or a function that calls FreeLibrary) during process termination, because this can result in a DLL being used after the system has executed its termination code.

Because Kernel32.dll is guaranteed to be loaded in the process address space when the entry-point function is called, calling functions in Kernel32.dll does not result in the DLL being used before its initialization code has been executed. Therefore, the entry-point function can call functions in Kernel32.dll that do not load other DLLs. For example, DllMain can create synchronization objects such as critical sections and mutexes, and use TLS.

Calling functions that require DLLs other than Kernel32.dll may result in problems that are difficult to diagnose. For example, calling User, Shell, and COM functions can cause access violation errors, because some functions load other system components. Conversely, calling functions such as these during termination can cause access violation errors because the corresponding component may already have been unloaded or uninitialized.

Because DLL notifications are serialized, entry-point functions should not attempt to communicate with other threads or processes. Deadlocks may occur as a result.

If your DLL is linked with the C run-time library (CRT), the entry point provided by the CRT calls the constructors and destructors for global and static C++ objects. Therefore, these restrictions for DllMain also apply to constructors and destructors and any code that is called from them.

[/quote:rbis19f7]

  • You must to post comments
0
0

pretty much sums it up

  • You must to post comments
0
0

Thanks for the answer.

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.