passage de paramètre dans l'appel d'une fonction venant d'une dll (C++ & Delphi)
Bonjour,
Le code suivant (écrit en C++) charge une fonction d'une dll (dll écrite en delphi), et, est censé m'afficher du texte passé en paramètre.
Celà ne fonctionne pas, le texte retourné semble toujours "null" ...
(Le chargement de la dll etc est ok)
Je ne comprend pas d'où vient l'erreur
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| private: System::Void bt_sbHelloParam_Click(System::Object^ sender, System::EventArgs^ e) {
typedef wchar_t* (*fct_sbHelloParam)(LPSTR txt);
fct_sbHelloParam fsbHelloParam;
fsbHelloParam = (fct_sbHelloParam)GetProcAddress(hInstLibrary, "_sbHelloParam");
if (fsbHelloParam){
LPSTR txt = "test";
std::wstring res = fsbHelloParam(txt);
MessageBox::Show(System::Convert::ToString(gcnew String(res.c_str())),"msg",MessageBoxButtons::OK,MessageBoxIcon::Question);
}else{
MessageBox::Show("GetProcAddress for _sbHelloParam failed !","msg",MessageBoxButtons::OK,MessageBoxIcon::Question);
}
} |
fonction en elle même (écrite en delphi)
Code:
1 2 3 4 5 6 7
| function _sbHelloParam(txt:PChar):Pchar; stdcall;
var
res : Pchar;
begin
StrPCopy(res,sbHelloParam(StrPas(txt))) ;
Result := res;
end ; |
PS: j'ai fais une fonction HelloWorld qui elle affiche un texte prédéfini dans la DLL delphi, et ça, ça marche.
Mais mon HelloParam est censé afficher un texte passé en paramètre, et c'est là que se pose mon problème (le passage de valeur en paramètres)