[.net] embedding unmanaged dlls?

Started by
1 comment, last by KyleL 18 years, 5 months ago
I have a generic image loader written in C#. It has modules for bmp, tga, etc written all in C#. Then I wanted to add OpenEXR support. This works fine using p/invoke and interop. No I want to make the whole thing a self contained assembly. This is the only reference I could find on the net. http://blogs.msdn.com/suzcook/archive/2004/10/28/249280.aspx using al.exe I created an assembly called "test.dll" that contains the OpenEXR dlls. I then added that to a simple console test program and added my test.dll namespace ConsoleApplication { class Program { static void Main(string[] args) { IntPtr test = ImfOpenInputFile("c:\image.exr"); Console.WriteLine(test); } [SuppressUnmanagedCodeSecurityAttribute()] [DllImport("IlmImf_dll.dll, test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")] public static extern IntPtr ImfOpenInputFile(string path); } } Running this give me An unhandled exception of type 'System.UnauthorizedAccessException' occurred in ConsoleApplication1.EXE Basically, I want to know if I can get all this stuff together into a single assembly for reuse.... Thx
Advertisement
My only comment on this would be that although it's nice to have all DLLs compiled into one library, it's not really nice when it comes to developing with that library. What if the programmer wants the OpenEXR DLL in their directory anyway, then you're just wasting space. What if the programmer wants an updated version of the OpenEXR library, they can't really easilly recompile your image loader with it. My advice would be to just use P/Invokes and Interop. It works, and it works beautifuly.
Rob Loach [Website] [Projects] [Contact]
I agree with Rod on this one for sure. If the P/Inoke works why mess with it? On the subject of your exception though I guess it would be helpful if you actually gave a little more information on this. Is there an inner exception? Whats the actual error message?

The UnauthorizedAccessException exception happens when you attempt to access something you don't have permissions for. This could be many different things especially with the type of thing you're doing. Get back with the extended information and we'll see what we can do to figure it out.

-Kyle

This topic is closed to new replies.

Advertisement