loader en c++ une dll build�e en C#
Bonjour,
Je cherche � utiliser une fonction d'une dll (build�e en C#) en c++. Voici la fonction en C#
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| namespace WMIString
{
public class WMI
{
public string GetString()
{
string maString= "";
//...
return maString;
}
}
} |
Dans les propri�t�s du projet, j'ai mis sous l'onglet applications : target framework : ".NET Framework 2". Sous assembly information, j'ai coch� "Make assembly COM-visible"
Dans les build options, j'ai coch�, "register for COM interop". Je devrais donc pouvoir utiliser cette dll dans un autre language, non?
J'ai ensuite builder la dll (appelons la madll.dll) sans erreur
Je veux ensuite charger cette dll depuis un projet c++ (j'utilise Qt �galement). Pour cela j'ai d�fini dans mon .h
Code:
typedef std::string (WINAPIV *WMI_GETSTRING)(VOID);
et dans mon .cpp je fais
Code:
1 2 3 4 5 6 7 8 9 10 11
| HINSTANCE hdll;
hdll = LoadLibraryW( L"madll.dll" );
if(hdll)
ui.textEdit->append("madll.dll loaded");
else
ui.textEdit->append("madll.dll not loaded");
WMI_GETSTRING WMIGetString;
WMIGetString= (WMI_GETSTRING)GetProcAddress( hdll, "GetString");
if( !WMIGetString)
ui.textEdit->append("cannot find function"); |
Cela compile, et je peux voir que la dll est bien charg�e correctement (le message "madll.dll loaded" s'affiche), cependant la fonction n'est pas trouv�e.
Pourquoi?
Merci d'avance pour votre aide