Création de DLL - Débutant
Bonjour a tous,
je dois créer une dll c++ comportant une fonction extremement simple (retourner une chaine de caractere).
Cette DLL doit être exportable ensuite dans un projet smartDevice C# (pour du Windows CE). Mais lors de l'appel de celle ci, j'ai l'erreur suivante:
Citation:
Error
ExceptionCode: 0xc0000005
ExceptionAdress: 0x017117dc
Writing: 0x0000c800
J'ai donc créé une DLL smartdevice. Les fichiers suivants on été générés:
dllTest.h - Resource.h - stdafx.h
dllTest.rc - dllTest.rc2
dllTest.cpp - dllTest.def - stdafx.cpp
voici le contenu des divers fichiers:
dllTest.h
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
| // dllTest.h*: fichier d'en-tête principal pour la DLL dllTest
//
#pragma once
#ifndef __AFXWIN_H__
#error "incluez 'stdafx.h' avant d'inclure ce fichier pour PCH"
#endif
#include "resource.h"
#include <string>
using namespace std;
// CdllTestApp
// Consultez dllTest.cpp pour l'implémentation de cette classe
//
class CdllTestApp : public CWinApp
{
public:
CdllTestApp();
// Substitutions
public:
virtual BOOL InitInstance();
string _stdcall getChaine();
DECLARE_MESSAGE_MAP()
}; |
dllTest.cpp
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 71
| // dllTest.cpp*: définit les fonctions d'initialisation pour la DLL.
//
#include "stdafx.h"
#include "dllTest.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//
//TODO*: si cette DLL est liée dynamiquement aux DLL MFC,
// toute fonction exportée de cette DLL qui appelle
// MFC doit avoir la macro AFX_MANAGE_STATE ajoutée au
// tout début de la fonction.
//
// Par exemple*:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // corps de fonction normal ici
// }
//
// Il est très important que cette macro se trouve dans chaque
// fonction, avant tout appel à MFC. Cela signifie qu'elle
// doit être la première instruction dans la
// fonction, avant toute déclaration de variable objet
// dans la mesure où leurs constructeurs peuvent générer des appels à la DLL
// MFC.
//
// Consultez les notes techniques MFC 33 et 58 pour plus de
// détails.
//
// CdllTestApp
BEGIN_MESSAGE_MAP(CdllTestApp, CWinApp)
END_MESSAGE_MAP()
// construction CdllTestApp
CdllTestApp::CdllTestApp()
{
// TODO*: ajoutez ici du code de construction,
// Placez toutes les initialisations significatives dans InitInstance
}
// Seul et unique objet CdllTestApp
CdllTestApp theApp;
// initialisation de CdllTestApp
BOOL CdllTestApp::InitInstance()
{
CWinApp::InitInstance();
return TRUE;
}
string _stdcall getChaine()
{
string str= "oki";
return str;
} |
dllTest.def
Code:
1 2 3 4 5 6 7
| ; dllTest.def : déclare les paramètres de module pour la DLL.
LIBRARY "dllTest"
EXPORTS
getChaine
; Les exportations explicites peuvent être placées ici |
et enfin, dans le projet en C#, voici comment je l'appelle:
Code:
1 2 3 4 5 6 7
| [DllImport("dllTest.dll")]
private static extern string getChaine();
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(getChaine());
} |
Merci pour votre aide