C ++ / CLI Dll with the problem of interacting with C #

I have 3 projects in one solution.

I have:

  • native C ++ dll,
  • C # Winform,
  • and a C ++ / CLI proxy without clean mode to perform communication between two other projects (and use the built-in function in managed C # code)

So when I run the application, everything works. But when I click the "Generer" button in my winform, which performs the NativeMethod :: Test () C ++ / CLI function, that it crashes, and I have this pop-up message:

An unhandled exception of type 'System.BadImageFormatException' occurred in System.Windows.Forms.dll

Additional Information: Failed to load file or assembly "EngineInterfaceWrapper.dll" or one of its dependencies. n'est pas une Win32 valide application. (Exception from HRESULT: 0x800700C1)

When I go to projects in Conf. Properties -> Linker -> Advanced: Target Machine, it is set with the value "MachineX86" for my native and managed C ++ DLL, and my WinForm is also in X86. I am tired of many configurations, but this does not work.

Edit:

The problem may be the "TradeEngine.h" header in the C ++ / CLI header: EngineInterfaceWrapper.h. Because when I disconnect my own C ++ Dll (and delete all the code in the CLI shell), if I create a solution it will work, but if "#include" TradeEngine.h "" is always in the CLI header, I will have this same mistake. Do you have an idea?

: - -

- . boost, ++.h. , Boost ( , ), Boost , .h .cpp . .

:

++

TradeEngine.h

#ifdef TRADEENGINE_EXPORTS
#define SYMBOL_DECLSPEC __declspec(dllexport)
#define SYMBOL_DEF
#else
#define SYMBOL_DECLSPEC __declspec(dllimport)
#define SYMBOL_DEF      __declspec(dllimport)
#endif

#pragma managed(push, off)
#include <curl/curl.h>
#include <boost\filesystem.hpp>

#include <boost\tokenizer.hpp>
#include <boost\lexical_cast.hpp>
#include <boost\thread.hpp>
#pragma managed(pop)

EXTERN_C SYMBOL_DECLSPEC void __stdcall Test(void);

TradeEngine.cpp

SYMBOL_DECLSPEC void __stdcall Test(void)
{
}

++/CLI

EngineInterfaceWrapper.h

#pragma once

#include "TradeEngine.h"

using namespace System;
using namespace System::Runtime::InteropServices;

namespace EngineInterfaceWrapper {

    public ref class NativeMethod
    {
    public:
        static void AjoutColonneDifferenceCourtClotureOuvertureReelle(void);
        static void Test();
    };
}

EngineInterfaceWrapper.cpp

#pragma region Includes
#include "stdafx.h"
#include "EngineInterfaceWrapper.h"
using namespace EngineInterfaceWrapper;

#include <msclr/marshal.h>
using namespace msclr::interop;
#pragma endregion

void NativeMethod::Test()
{
    ::Test();
}

# Winform

Program.cs

namespace TradeInterface
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Form1.cs

generer_Click() - , , Generer.

using 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;
using EngineInterfaceWrapper;

namespace TradeInterface
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void generer_Click(object sender, EventArgs e)
        {
            NativeMethod.Test();
        }
    }
}
+5
2

32- dll 64- . , x86, WoW64.

+4

:

http://marc.info/?l=boost-users&m=123425857320026

→ C/++ → → BOOST_ALL_DYN_LINK, DLL. , DLL , . . boost_thread-vc90-mt-gd-1_XX.dll MyApp/bin/Debug.

+7

All Articles