Проблемы с использованием C ++ DLL при запуске C# UI Application [закрыто]C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Проблемы с использованием C ++ DLL при запуске C# UI Application [закрыто]

Сообщение Anonymous »

I recently met with a curious problem when using C++ Dll when using C# application

"System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format. (0x8007000B)'"

I searched around the web and found solutions like making Конечно < /p>

DLL создан как та же самая конфигурация (т.е. x86 или x64) < /li>
Убедившись, что функции C ++, которые вы называете, не имеют проблемы < /li>
< /ol>
Для решения 1, у меня есть другие функции в DLL, что нет. Для Soln 2 я попытался создать его как пустую функцию C ++ в DLL, комментируя исходные коды. Тем не менее, проблема сохраняется. Нужна кто -то добрый помощь, чтобы указать на проблему или предоставить некоторые идеи для устранения неполадок < /p>
Вот мой C ++ DLL. Файл заголовка < /p>
#pragma once
#ifndef _UTIL_DLL_H
#define _UTIL_DLL_H

#include
#include
#include
#include
#include
#include
#include

#include "boost/iostreams/device/mapped_file.hpp"
#include
#include
#include
#include
#include
#include

// Warn about use of deprecated functions.
#define GNUPLOT_DEPRECATE_WARN
#include "gnuplot-iostream.h"
#include "../../../../OneDrive/Documents/GitHub/gnuplot-iostream/gnuplot-iostream.h"

#define EXPORT_API __declspec(dllexport)

extern "C" {
//EXPORT_API void plot(const char* file, int xIdx, int yIdx);
EXPORT_API int add(int a, int b);

EXPORT_API void SayHello();

EXPORT_API void plot();
}

#endif
< /code>
c ++ cpp < /p>
// Util.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "Util.h"

extern "C" {

EXPORT_API int add(int a, int b)
{
return a + b;
}

EXPORT_API void SayHello() {
std::cout
using CsvHelper;
using CsvHelper.Configuration;
using System;
using System.Diagnostics;
using System.Formats.Asn1;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using static System.Net.Mime.MediaTypeNames;

namespace WpfTutorialSamples.XAML
{

public partial class EventsSample : Window
{
private const string dllpath = @"C:\Users\water\source\repos\WPF\x64\Debug\Util.dll";

[DllImport(dllpath, CallingConvention = CallingConvention.Cdecl)]
public static extern int add(int a, int b);

public static extern void plot();

// this is ok
private void Button_Hello(object sender, RoutedEventArgs e)
{
uiTextBox1.Text = add(1, 2).ToString();

}

// this gives the above problem
private void Button_Plot(object sender, RoutedEventArgs e)
{
plot();
}

}
}


Подробнее здесь: https://stackoverflow.com/questions/797 ... pplication
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»