简体   繁体   中英

How p/invoke call function using only but C++ need the .a/.lib/.o files?

How is even possible to .NET's P/invoke call a function within a DLL using only the dll file but for C++ you can't do it without the .a/.lib / .o files?

Background:

I'm trying to use a function from a dll "written" in C++ from a C++/CLI application but I've told that only the dll file plus header isn't enough I need to the .a/.lib / .o files too. How this dll was compiled using minGw and C++/CLI doesn't support .a files but only .lib s I'll have to recompile this dll using MSVC compiler/linker. So I wonder why does this "simple" thing in C# works:

[DllImport("foo.dll",
        CallingConvention = CallingConvention.Cdecl,
        EntryPoint="_Z9getNumberv")]
    public static extern int GetNumber();

But a dll in and for C++ it take more work/need to files. I'm a begginer so I'm probably missing something.

You can use GetProcAddress in C++ and invoke directly with that. That's similar to what P/Invoke does.

The use of an import library is to enable the standard linker to work (whereas P/Invoke and GetProcAddress bypass the linker).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM