Unable to load DLL the specified procedure could not be found. (Exception from HRESULT: 0x8007007F)

0

For a long time I have a problem with a project that I have to implement in mine, I'll explain it to you.

My goal is to call a C ++ class from a C # application (Project 1), the problem is that the C ++ project (Project 3) is not compatible with CLR.

What I have done so far has been created an intermediate project also in unmanaged C ++ (Project 2) to be compatible with the project 3.

Project 2 consists of a very simple method that initializes a class from project 3 and uses this object for different operations.

I'm working in Visual Studio and it does not give me an error when compiling, but at run time I get the following error:

Unable to load the DLL file 'PROJECT-ROUTE \ Project2.dll': The specified procedure could not be found. (Exception from HRESULT: 0x8007007F) in project1.process ()

The thing is that the previous error comes out only when within the project2 method I initialize the class from project 3, if I comment the initialization line then it goes well, I can not understand why between 2 C ++ projects of the same type gives me this type of problems.

Can somebody help me?

thank you

C# Code (Project 1)

    private const string DllFilePath = @"PATH_TO_DLL\Proyect2.dll";

    [DllImport(DllFilePath, CallingConvention = CallingConvention.Cdecl, EntryPoint = "process")]
    public extern static void process();

    [HandleProcessCorruptedStateExceptions]
    public static string Prox(string a, string b)
    {
        string str = "OK";
        try
        {

            process();
        }
        catch (System.AccessViolationException exception)
        {
            return exception.Message + " " + exception.StackTrace;
        }
        catch (Exception exception)
        {
            return exception.Message + " " + exception.StackTrace + " ";

        }

        return str;
    }
}

Middle proyect Unamanged C++ Code (Project 2)

Project2.h

    #include <stdexcept>
    #include "Project3.h"
    using namespace std;


    namespace FinalProcess
    {
        extern "C" { __declspec(dllexport) void __cdecl  process(); }
    }

Project2.cpp

    #include "Project2.h"
    #include <iostream>
    #include <chrono> // To measure execution time

    namespace FinalProcess
    {
        void process()
        {

            OCTA::Analyzer& ld = OCTA::Analyzer::getInstance(); // <-- Singleton
    // if I comment this line then it goes well
        }
    }
c#
c++
visual-studio
dll
dllimport
asked on Stack Overflow Feb 5, 2019 by code lost • edited Feb 5, 2019 by code lost

1 Answer

1

Assuming that the information that you present here is correct (and I have my doubts because you've not copied it verbatim as can be seen from the DLL name of Proyect2.dll) then the error cannot be that the function process is not found. In which case the error has to be in the linking to Project3.

Your Project2.dll is presumably attempting to link to Project3.dll and to a function that is not exported from Project3.dll. That would explain the behaviour that you report. This would happen typically if the Project3.lib file that you linked when building Project2.dll did not match the Project3.dll file found by the executable at runtime.

Make sure that the version of Project3.dll that is being loaded is up to date and matches the .h and .lib files you used to build Project2.dll.

Rather than give an absolute path of the DLL in your C# code, you just the file name of the DLL. Place both DLLs in the same directory as your C# executable.

answered on Stack Overflow Feb 5, 2019 by David Heffernan

User contributions licensed under CC BY-SA 3.0