Sign in to follow this  

[.net] embedding unmanaged dlls?

This topic is 4415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this