views:

437

answers:

2

Hi..!

I have a native C++ application (no fancy .Net stuff just C++). However it uses some optional .Net assemblies through mixed mode wrapper dll files. These dlls are loaded using delay load. Thing with mixed mode wrappers is they need to be fully trusted in order to load. So when the application try to use the dll if it is not there or if it is not trusted entire thing crashes with a nasty error message.

But i my case as long as my main application is concerned it can live without these dll files. So I need a way to check if these dlls can be loaded (files are there and trusted). In order to do this I tried to put a dummy call to one of the dll functions within a try catch block hoping the catch the exception but it still crash with 'module not found' exception.

we also tried replacing unhanded exception filter with a custom one but still no luck.

we also tried to use LoadLibrary method to first load the dll and check the return value. But that function load the Dll even if it is not trusted but crash when we try to do a method call.

I dont think that this is an unsolved problem. How hard can it be to check if a dll can be used without actually trying to load it and end up crashing? Any ideas?

+1  A: 

If all methods fail, try running a separate process (i.e. simple command-line app) that will try to load the library, then analyze its return code.

But, did you try structured exceptions handling - i.e. __try/__catch, not try/catch? See here.

queen3
A: 

I had the idea of using a separate process to test the dll first and see if it runs in to any errors. I don't want to use that in my app cos it was not really a clan solution. but the __try, __except approach worked with delay load dll calls. I didn't even have to use LoadLibrary. Thanks.

Rakhitha