有帮助吗?

解决方案

Your problem here is, when the first call to a delay loaded function is made, the applications default activation context is the current context.

What you need to do is create an activation context: CreateActCtx pointing at your own manifest (hinstance+resource id is possible I think).

Then, wrap all, or at least the very first, call to the dll with ActivateActCtx (and the corresponding deactivate function) to ensure the correct assemblies are searched.

In theory you could just embed the code to activate the appropriate context in the delayload helper function.

其他提示

This behaviour is by design, unfortunately. Essentially, when you specify /DELAYLOAD, you're just instructing the linker to insert the LoadLibrary and GetProcAddress calls for you. As a result, the behaviour when delay loading a DLL is the same as loading that DLL dynamically with LoadLibrary.

MSDN describes some of the consequences. On the plus side, you can override the default behaviour. I'd recommend writing your own delay load helper function.

FARPROC WINAPI __delayLoadHelper2(PCImgDelayDescr pidd, FARPROC * ppfnIATEntry)
{
    //...
}

The linker will insert calls to this function whenever it needs to resolve an entry point in a delay loaded DLL. Your version could implement a custom search for your private assemblies. Here's additional information about the helper function on MSDN.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top