Thread: DLL import from resource?

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    1

    DLL import from resource?

    I am pretty new to C# and I'm wondering if it's possible to directly load a DLL from resource? Right now I'm extracting the embedded DLL and then loading the function like this.
    Code:
    // Function to take resource name and extract it to file location of second parameter
    ExtractResourceToFile( "D3DWRAP.embed", "D3DWrapper.dll" );
    
    [System.Runtime.InteropServices.DllImport("D3DWrapper.dll")]
    private static extern void createoverlay();
    I would much prefer to do this..
    Code:
    [System.Runtime.InteropServices.DllImport("D3DWRAP.embed")]
    private static extern void createoverlay();
    So is it possible to load the DLL function directly from the embedded resource or do I need to extract it first?
    Last edited by thenoobie; 11-08-2011 at 11:31 AM.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Not without serious hackery (i.e. writing your own implementation of LoadLibrary()).

    A commercial package does exist which lets you pack DLLs into your EXE and use them without needed to write them to disk, but I don't remember what it's called or what it costs (it isn't free).

    The simplest is what you suggested yourself, write the resource to disk as a DLL and then open it with LoadLibrary(). Note that this is considered "sketchy" behavior and you may trigger antivirus software.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Indeed that will trigger anti-virus software. Why do you need to rely on this type of behavior? Perhaps there is a better approach.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dll Import
    By dankalim in forum C Programming
    Replies: 3
    Last Post: 06-29-2007, 09:37 AM
  2. How to import a DLL
    By chad101 in forum C++ Programming
    Replies: 3
    Last Post: 05-31-2007, 05:23 PM
  3. DLL Import
    By Hyder Ali in forum C# Programming
    Replies: 5
    Last Post: 06-14-2004, 12:36 AM
  4. ASM dll import
    By borko_b in forum C Programming
    Replies: 1
    Last Post: 04-03-2003, 12:15 AM
  5. Import Dll
    By Shakespeare in forum C++ Programming
    Replies: 2
    Last Post: 01-27-2003, 05:40 AM