开发者

Trying to load a DLL with LoadLibrary and get R6034 "An application has made an attempt to load the C runtime library incorrectly"

I'm writing a wrapper p开发者_StackOverflowrogram 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);

}


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.


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.


Also, you may try adding this into the code:

#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b'\"")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜