I'm having a linking problem that looks just like this one: http://www.experts-exchange.com/Programming/Languages/.NET/Q_23332235.html
that unfortunately didn't end up getting resolved.
I have code in an unmanaged C++ project that needs to call code in a C# project (i.e, managed code). To that end I have created a 'bridge' project in CLR/C++ which will wrap the C# code and give the unmanaged C++ code something to call into. There are several descriptions of how to do this on the web and I've been working through this one stackoverflow.com/question
Bridge Project (C++/CLR)
// This is the main DLL file and is named MixedModeDLL.cpp
double CalculateProduct(double x, double y)
ManagedClass^ t = gcnew ManagedClass();
double z = t->multiplyTwoValues(x, y);
That's it. The header file CppInterface.h is pretty simple. It just exports the routine CalculateProduct which calls the C# code (via machinations in MixedModeDLL.h which I'm happy to share but seems a distraction to the problem at hand) like this:
extern "C" __declspec(dllexport) double CalculateProduct(double x, double y);
It should be noted that I have successfully called the CalculateProduct(...) routine from a C# driver program which implies that CalculateProduct(...) can be accessed by outside code (i.e., it looks like it is being exported). I did this using this code:
private void button4_Click(object sender, EventArgs e)
// Test of calling into the managed C++ (CLR) MixedModeDLL DLL.
double h = 2.5;
double k = 6.0;
double p = NR.CalculateProduct(h, k);
where NR is a C# class in the driver code defined like this:
[DllImport("MixedModeDLL.dll", EntryPoint = "CalculateProduct")]
public static extern double CalculateProduct(double x, double y);
In the C++ code I have a line that says the following:
extern "C" __declspec(dllexport) void testCPPcallingCS()
double z = CalculateProduct(4.9, 3.2);
(Note: (the export here is so that my C++ driver program can get access to testCPPcallingCS())
testCPPcallingCS() is defined in a module that includes a #include statement for header file that mirrors CppInterface.h described above; where that one says export, this one says import. That is:
extern "C" __declspec(dllimport) double CalculateProduct(double x, double y);
The compiler has no problem with this, but the linker gets fussy. It reports two errors:
error LNK 2019: unresolved external symbol __imp_CalculateProduct referenced in function testCPPcallingCS
error LNK1120: 1 unresolved externals
It almost looks like the name of the CalculateProduct routine has been decorated with a prefix of __imp_. I have checked that all of the expected DLLs are in the output directory (...\Driver_CPP\x64\Debug)
and that the *.lib of the 'Bridge' CLR/C++ code (i.e., MixedModeDLL.lib) is located in the same directory. In the aforementioned link the author says to insure that the linker is told to 'use the generated .lib file when linking'. I have checked the Properties of MixedModeDLL and the native C++ project and see nothing that implies to me that the .lib file is not being used.
I'm developing using Microsoft Visual Studio 2010 (my C# driver routine is written in MSVS 2012) on a Windows 7 computer. MixedModeDLL and the unmanaged C++ DLL are targeted to an x64 platform.