The problem is simple. I have LoadLibrary on my c++ app and I want to load c# library but I don't know the entry point.

If it's CLI, just add it as a reference in your project settings, then add

using namespace ThatNamespace;

and you're done.

I think you didn't get my point. I have this on my c++ CLI.

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

static HMODULE hLibrary;

BOOL APIENTRY DllMain (HINSTANCE hInstance, DWORD reason, LPVOID reserved) {
    switch (reason) {
        case DLL_PROCESS_ATTACH:
            hLibrary = LoadLibrary(L"something.dll");
        break;
        case DLL_PROCESS_DETACH:
            FreeLibrary(hLibrary);
        break;
    }

    return true;
}

Now that something.dll is my C# Class Library. So, I want to know the entry point of the application of what LoadLibrary execute on that dll.

Yeah whatever, how to get the entry point in C#?

Thanks for that. I've learned few things. But it's not related to my problem.

LoadLibrary

> hLibrary = LoadLibrary(L"something.dll");

OK. I'm totally confused. The above statement indicates that you are attempting to load a class library named something.dll which is managed code using a unmanaged Win32 API, LoadLibrary. I just don't see how that could possibly work. It's like trying to put a square peg in a round hole.

Entry points are different between managed and unmanaged code. In unmanaged code an (ordinal) entry point would point to the origination of a function such as the starting point of DllMain. Thus, there could possibly be multiple entry points in an unmanaged DLL. One entry point for each function. In managed code such as your class library, it (the entry point) would point to the beginning of your class library. There would only be one entry point for your class library. Not multiple entry points as in one entry point for each function in unmanaged code. CLR doesn't even care about entry points because all the information it needs about your class library can be found in the metadata. You can use the ILDASM.exe utility to veiw all the metadata of your class library. Entry points are used more of a matter of convenience in managed code, primarily to point you to the starting point of an application.

Thus, AFAIK, the COM interface method is the only way to resolve your problem if you plan to go the unmanaged code route. Otherwise, you may want to use managed C++ and include the namespace of the class library in your managed C++ app to simply resolve your problem.

Great post. Can you please show an example on how to solve it?

Here's a link to calling a managed dll from unmanaged code.

And listed below is a sample of calling a managed dll from managed code since I couldn't find a really simple basic examples on the internet.

Source: myDll.cs

    //Compile:  csc /target:library /out:myDll.dll mydll.cs
    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace myDllTest
    {
        public class AddNumbers
        {
            public int addemup(int x, int y)
            {
                return (x + y);
            }
        }
    }

Source: test.cpp

  // compile: cl.exe /clr test.cpp
#include <stdio.h>

#using <mydll.dll>

using namespace myDllTest;

int main(void)
{
    AddNumbers addit;
    printf("%d\n", addit.addemup(45,89));
    return 0;
}
Comments
Thanks alot for this post.
This question has already been answered. Start a new discussion instead.