Подключить dll на c++ к c# (DllImport)
Формулировка задачи:
Есть dll написанная на с++, нужно подключить к c#.
Код c++
Откомпилировал Release x86, получил файл mydll.dll.
Пытаюсь эту dll подключить к c#.
Код c#
Откомпилировал Release x86, при вызове функции test_Func(1); выдает ошибку:
#include <Windows.h>
//#include <TlHelp32.h>
#include <tchar.h>
#include <conio.h>
__declspec(dllexport)
int test_Func(int ret)
{
return ret;
}LIBRARY "mydll"
EXPORTS
test_Funcusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace dll_test
{
public partial class Form1 : Form
{
#region Наша dll
//[DllImport("mydll.dll")]
//private static extern int test_Func(int set);
//[DllImport("mydll.dll", CharSet = CharSet.Unicode, EntryPoint = "test_Func")]
// private static extern int test_Func(int ret);
[DllImport(@"mydll.dll")]
static extern int test_Func(int a);
#endregion
public Form1()
{
InitializeComponent();
}
#region Событие - нажатие клавиши (Отправить)
private void bt_send_Click(object sender, EventArgs e)
{
test_Func(1);
}
#endregion
}
}Ошибки.
Откомпилировал Release Any CPU, при вызове функции test_Func(1); выдает ошибку:Необработанное исключение типа "System.BadImageFormatException" в dll_test.exe Дополнительные сведения: Была сделана попытка загрузить программу, имеющую неверный формат. (Исключение из HRESULT: 0x8007000B)
Необработанное исключение типа "System.EntryPointNotFoundException" в dll_test.exe Дополнительные сведения: Не удается найти точку входа "test_Func" в DLL "mydll.dll".
Буду благодарен за любую помощь) И даже попытки помочь приветствуются
Решение задачи: «Подключить dll на c++ к c# (DllImport)»
textual
Листинг программы
[DllImport(@"путь до библиотеки", CallingConvention = CallingConvention.Cdecl)] static extern int test_Func(int a);