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
|
// cliWrapper.h
#pragma once
#include "personne.h"
#include <windows.h>
#include <vcclr.h>
using namespace System;
#pragma comment (lib, "libCppForInterop3.lib")
namespace conversion{
static string convertStringToStlString (String ^ chaine)
{
char * chaineChar;
pin_ptr<const wchar_t> wch = PtrToStringChars(chaine);
int taille = (chaine->Length+1) * 2;
chaineChar = new char[taille];
int t = WideCharToMultiByte(CP_ACP, 0, wch, taille, NULL, 0, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, wch, taille, chaineChar, t, NULL, NULL);
std::string chaineSTL = chaineChar;
delete chaineChar;
return chaineSTL;
}
}
namespace cliWrapper {
public ref class CliWrapperCPersonne
{
private:
CPersonne * cp;
public:
CliWrapperCPersonne(String ^nom, String ^prenom)
{
string nomStd = conversion::convertStringToStlString(nom);
string prenomStd = conversion::convertStringToStlString(prenom);
cp = CPersonne_New(nomStd, prenomStd);
}
~CliWrapperCPersonne()
{
CPersonne_Delete(cp);
}
protected:
!CliWrapperCPersonne()
{
CPersonne_Delete(cp);
}
public:
System::Void Affiche()
{
cp->afficheNomPrenom();
}
};
} |
Partager