Unable to load DLL 'DPDFRenderNative_x64': The specified module could not be found.

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF PrintManager for .NET (v4)  /  Re: Unable to load DLL 'DPDFRenderNative_x64': The specified module could not be found.

DynamicPDF PrintManager for .NET (v4) Forum

Hi Team,

I am getting the following exception 'Unable to load DLL 'DPDFRenderNative_x64'  while printing. In our application there is an exe(lets say A.exe), which in  turn having its business logic which is in another dll(lets say B.dll) which is responsible for calling the DynamicPDF dll. When I place the DPDFRenderNative in the same directory as A.exe everything runs fine but when I place this in the directory of B.dll it doesn't work. I cannot put third party party Dlls in the root folder of the application which is same as of A.exe. Can you please help how to fix this.
Posted by a ceTe Software moderator
Hello,

Here is one method that will likely work for you. Set your own current directory through code to a directory containing the native DLL. Then make a call to our library that loads the native DLL, such as the PrintJob constructor. You can then set the current directory back to the original path if it is needed by something else in your applications. Please note that this only needs to be done the first time our library is used.

Here is a code sample:

           String defaultCurrentDir = System.IO.Directory.GetCurrentDirectory();
            //Set the current directory and load the native DLL file.
            System.IO.Directory.SetCurrentDirectory(@"Folder path");
            PrintJob printJob = new PrintJob("Printer name", @"Input PDF file path", 1, 1);
            //Once the native DLL is loaded you can change it back to original.
            System.IO.Directory.SetCurrentDirectory(defaultCurrentDir);
            printJob.Print();

We are continuing to look into this and will post an update if we find an alternate or preferred way of doing this.

Thanks,
ceTe Software Support Team
Hi Team,

This will not work in our multi-threaded application because as per MSDN "Multithreaded applications and shared library code should not use the SetCurrentDirectory function and should avoid using relative path names".
Can you please provide a better solution to avoid this problem.

Thanks and Regards,
Akash Choudhary
Posted by a ceTe Software moderator
Hello,
 
Here is another method to load the native DLL which is among the list provided in the link here. Please refer to the documentation provided in the link above and use it accordingly in your application.

Below is the code sample.

    [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetDllDirectory(string lpPathName);
    static void Main(string[] args)
    {
        SetDllDirectory(@"Folder path");
        int err = Marshal.GetLastWin32Error();
        PrintJob printJob = new PrintJob("Printer name", @"Pdf file path", 1, 1);
        printJob.Print();
    }

Thanks,
ceTe Software Support Team

All times are US Eastern Standard time. The time now is 11:02 PM.