Though I don't know VC++ have I've searched the net. Please check it...
The VC++ code:-
a)plus.h:
- #ifndef PLUS_H
- #define PLUS_H
- int __declspec(dllexport) add(int a, int b);
- #endif
b)plus.cpp:
- #include "pch.h"
- #include "plus.h"
- int add(int a, int b)
- {
- return a + b;
- }
Now in C#
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Test t = new Test();
- int fooPtr = Test.add(5, 9);
- int LENGTH = 1;
- var foo = new int[LENGTH];
-
- MessageBox.Show(fooPtr.ToString());
- }
- }
- public class Test
- {
- [DllImport("F:/TestMultipleProject/FirstDll/Debug/FirstDll.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
- public static extern int add(int a, int b);
- }
Reference of VC ++ project is added to C# and they both reside in same solution
NOW PROBLEM is unable to find an entry point named add in the dll....