none
How to access gsdll32.dll in C++ or C++/CLI project RRS feed

  • Question

  • I have written a program that creates chess diagrams using post script.  I want to convert the resulting *.eps file to an equivalent *.jpg file using ghost script.  I have succeeded in doing this in a C# project but I cannot get it to work in C++ or C++/CLI, either one.  The problem is in getting access to the gsdll32.dll methods.

    In C# I use this code:
            [DllImport ("gsdll32.dll", EntryPoint = "gsapi_new_instance")]
            private static extern int CreateAPIInstance (out IntPtr instance, IntPtr caller);
    My attempts to use DllImport in C++ have failed.

    In a C++/CLI project I get the following error when trying to add a reference:

    Could not add a reference to 'S:\UseGhostScript\bin\Debug\gsdll32.dll' as it is not of a type or version current project can use.

    In a C++ project I added the gsdll32.dll as a 'Solution item' and when building get the error message:

    Error LNK1107 invalid or corrupt file: cannot read at 0x2B8 UseGhostScriptConsole S:\ScruffySoft\UseGhostScriptConsole\gsdll32.dll

    So the question is: how do I get access to the ghost script DLL?

    Thanks,
    Dick
    Friday, September 18, 2020 3:38 PM

Answers

  • Do you have the associated .h and .lib files for this library?

    It is also possible to use [DllImport] in C++/CLI (https://docs.microsoft.com/en-us/cpp/dotnet/calling-native-functions-from-managed-code?view=vs-2019), but make sure that you choose the right configuration: 32- or 64-bit.

    You can also consider the method based on LoadLibrary, GetProcAddress, etc.

    An intermediate solution is to build a C# Class Library, where you already know how to access the DLL, and reference it in C++/CLI. The public classes from C# can be used in C++/CLI directly.



    • Edited by Viorel_MVP Friday, September 18, 2020 5:25 PM
    • Marked as answer by Dick Swager Friday, September 18, 2020 9:59 PM
    Friday, September 18, 2020 5:24 PM

All replies

  • Do you have the associated .h and .lib files for this library?

    It is also possible to use [DllImport] in C++/CLI (https://docs.microsoft.com/en-us/cpp/dotnet/calling-native-functions-from-managed-code?view=vs-2019), but make sure that you choose the right configuration: 32- or 64-bit.

    You can also consider the method based on LoadLibrary, GetProcAddress, etc.

    An intermediate solution is to build a C# Class Library, where you already know how to access the DLL, and reference it in C++/CLI. The public classes from C# can be used in C++/CLI directly.



    • Edited by Viorel_MVP Friday, September 18, 2020 5:25 PM
    • Marked as answer by Dick Swager Friday, September 18, 2020 9:59 PM
    Friday, September 18, 2020 5:24 PM
  • Still working on the C++ solution but the the idea of creating a C# library works fine.  I don't know why I did not think of that myself.
    Friday, September 18, 2020 9:59 PM