views:

353

answers:

2

I'm writing a wrapper program that loads Winamp input plugins. I've got it working well so far with quite a few plugins, but for some others, I get an error message at runtime when I attempt to call LoadLibrary on the plugin's DLL. (It seems to happen mostly with plugins that were included with Winamp.) A dialog appears and gives me the error code and message above. This happens, for example, with the in_flac.dll and in_mp3.dll plugins (which come with Winamp). Any ideas on how I can remedy this situation?

EDIT: This basically iterates through the plugins in a directory and attempts to load and then free each one. Some plugins produce the error I mentioned above, while others do not.

wstring path = GetSearchPath();

FileEnumerator e(path + L"in_*.dll");

while(e.MoveNext()) {

    wstring pluginPath = path + e.GetCurrent().cFileName;

    MessageBoxW(NULL, pluginPath.c_str(), L"Message", MB_OK);
    HINSTANCE dll = LoadLibraryW(pluginPath.c_str());
    if(!dll) {

        pluginPath = wstring(L"There was an error loading \"") + wstring(e.GetCurrent().cFileName) + L"\":\n" + LastErrorToString();
        MessageBoxW(NULL, pluginPath.c_str(), L"Error", MB_OK);

        continue;

    }

    FreeLibrary(dll);

}
+1  A: 

there can be many reason... put your code here for clarification... one of the many solution might be is Rebuild your application with a manifest. Building an application with Visual Studio automatically puts the manifest into the resulting EXE or DLL file. If you are building at the command line, use the mt.exe tool to add the manifest as a resource. Use resource ID 1 if building an EXE, 2 if building a DLL.

mihirpmehta
Added code snippet.
nonoitall
go through it... in most of the cases it'll solve the problem..http://msdn.microsoft.com/en-us/library/ms235342%28VS.80%29.aspx
mihirpmehta
+1  A: 

Starting from Visual Studio 2005, the C/C++ runtime MUST be put in the Windows side-by-side cache (C:\windows\WinSxS), so putting the CRT DLL's next to your exe doesn't work anymore (with one exception, see later). You MUST also refer to the CRT DLL's via a manifest file. This manifest file is generated by the linker and will have a name like myexe.exe.manifest or mydll.dll.manifest. Distribiute this manifest with your application/DLL or link it in the exe/dll using the mt command.

The side-by-side cache and the manifest file system were introduced in Windows XP and are mainly intended to solve the DLL hell and to increase security.

Not referring to the CRT using a manifest or not putting the CRT in the side-by-side cache will generate error 6034.

If you still want to put the CRT DLL's next to your application, you could also use private assemblies, which means creating a kind of mini-side-by-side cache in the folder of your application. You can find additional information on MSDN.

Patrick
Just came back from Wikipedia and learned pretty much exactly what you just said there. :-) Anyone know if there's a built-in way to include a manifest using Code::Blocks or do I need to manually include it with mt.exe after the executable is built?
nonoitall
The manifest can be converted to a resource and then be linked in directly. See http://msdn.microsoft.com/en-us/library/ms235591.aspx.
Patrick
Having a hard time figuring out where mt.exe is supposed to come from, but I managed to create a manifest that works using the Manifest Generation and Editing Tool from the Windows SDK. Still seems like a bunch of voodoo to me, but it works for now so I'll worry about it someday when/if I ever make this app public. Thanks!
nonoitall