Probleme Wrapper c++ -> C#.
Salut,
Je dois faire un wrapper c++ vers c#. J'ai fais un petit example avec une methode qui returne tab double . J'ai le probleme avec declenchement cette methode dans le c#.
Si c'est possible quel'un peut regarder mon code ?
Je serai reconnaisante de l'aide ;)
Mon code dans le c# :
Form1.cs :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
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;
namespace WrapperTab
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Run();
}
public static void Run()
{
double[] dane = new double[30];
#region Dane
dane[0] = 2.3;
dane[1] = 2.4;
dane[2] = 4.5;
dane[3] = 5.5;
dane[4] = 5.5;
dane[5] = 6.7;
dane[6] = 5.6;
dane[7] = 4.5;
dane[8] = 5.5;
dane[9] = 4.4;
dane[10] = 2.3;
dane[11] = 2.3;
dane[12] = 4.5;
dane[13] = 5.5;
dane[14] = 5.5;
dane[15] = 6.7;
dane[16] = 2.4;
dane[17] = 4.5;
dane[18] = 5.5;
dane[19] = 5.5;
dane[20] = 6.7;
dane[21] = 5.6;
dane[22] = 4.5;
dane[23] = 5.5;
dane[24] = 4.4;
dane[25] = 2.3;
dane[26] = 2.3;
dane[27] = 4.5;
dane[28] = 5.5;
dane[29] = 5.5;
#endregion Dane
double[] wynik = new double[30];
wynik = UnsafeNativeMethods.fun(dane); // ?????
for (int i = 0; i < 30; i++)
{
MessageBox.Show(wynik[i].ToString());
}
}
}
} |
Class1.cs
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace WrapperTab
{
internal static class UnsafeNativeMethods
{
const string dllLocation = "D:\\TestWrapperTab\\WrapperTab\\WrapperTab\\TestWrapperTab.dll";
[DllImport(dllLocation)]
public static extern double[] fun(double[] tab1);
}
} |
code in c++ :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include "stdio.h"
#include <iostream>
extern "C"
{
__declspec(dllexport) double* fun(double tab1[30])
{
double tabWyn[30];
for(int i =0; i<30;i++)
{
tabWyn[i]=tab1[i] + 5;
}
return tabWyn;
}
} |
Amicalement
agatte