-2

I've a very interesting problem. It's sounds very easily, but I didn't finf any information about it.

I've a C# solution with excel Add-in and winforms application and library project with only one method.

project with library have next code:

[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr LoadLibrary(string filename);
public sealed class LibraryInfo
{
    public readonly IntPtr Handle;
    public LibraryInfo(string dllName)
    {
        Handle = LoadLibrary(dllName);
    }
}
public LibraryInfo GetLib(string name)
{
    return new LibraryInfo(name);
}

Look's like simple. So I've a call of that method from add-ins and from WinForms

I've a Dll, builded for x64 platform and x86 platform.

And now magic: LoadLibrary returns error code 127 only when I run it from Add-in and x64 configuration and on excel-2016(x64, ofcourse). When I run it on x86, or winform (both x86 and x64) it works. And it is not all, when I run it on Excel 2013 it's works fine too!!!

mayby somebody knows?

IInspectable
  • 46,945
  • 8
  • 85
  • 181
qpIlIpp
  • 29
  • 4
  • Would it be possible to format your code as code. The edit window has help for how to do that. That way you can get decent syntax highlighting and indentation. As it stands, the code here is hard to read. – David Heffernan Oct 28 '15 at 12:23

2 Answers2

1

Error code 127 is ERROR_PROC_NOT_FOUND.

The specified procedure could not be found.

Typically that means that something is calling GetProcAddress which is failing because the module in question does not export a function of the specified name.

Exactly where that is happening cannot be discerned from the code that you supplied. Unfortunately you did not supply very much code, and did not supply the code that you are using. That much can be discerned from the fact that you mention an error code in spite of the code in your question performing no error checking.

It could be that code you did not show is calling GetProcAddress and failing. Or it could be that the loader is yielding that error code whilst resolving the dependencies of the library you load.

So, what I've stated above is a broad explanation for the behaviour that you report. Anything more specific would require the actual code in use, but only you have that code.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
-1

Problem solved.

I ve a dependent dll for my, called "Chart", so excel 2016 have "chart.dll", 2013 - not. The solution is rename my "chart.dll" and rebuild both of dlls.

qpIlIpp
  • 29
  • 4
  • This refers to a lot of details that are simply missing from the question. As such, if you think that this is the answer to your question you need to do one of two things. Edit the question to provide all the necessary details such that this answer can be inferred by us and not just by you. Or, if you don't want to do that, delete the question. In its current form, it is probably of little use to you. – David Heffernan Oct 28 '15 at 15:32