According to Delphi to C++ types mapping, Delphi equivalent of wchar_t*
is PWideChar
.
DLL Header File:
#include <s2wc.h>
#include <wc2s.h>
#include <windows.h>
using namespace std;
#ifdef __cplusplus
extern "C"
{
#endif
wchar_t* DLL_EXPORT Fonksiyon(wchar_t* wchtAlinanMesaj);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
DLL Cpp File:
#include "main.h"
//String
string strMesaj;
//wchar_t*
wchar_t* wchtGonderilecekMesaj;
// a sample exported function
wchar_t* DLL_EXPORT Fonksiyon(wchar_t* wchtAlinanMesaj)
{
WC2S(strMesaj, wchtAlinanMesaj);
strMesaj = strMesaj + "Kaya";
wchtGonderilecekMesaj = S2WC(strMesaj);
return wchtGonderilecekMesaj;
}
Delphi Codes:
//type
//TFonksiyon = function(pwchMetin: PWideChar): PWideChar; cdecl;
procedure TForm1.Button1Click(Sender: TObject);
var
dll: THandle;
fonksiyonum: TFonksiyon;
pwchAlinanMesaj, pwchGonderilecekMesaj: PWideChar;
begin
dll := LoadLibrary('deneme.dll');
if(dll >= 32) then begin
fonksiyonum := GetProcAddress(dll, 'Fonksiyon');
pwchGonderilecekMesaj := PWideChar(Edit1.Text);
pwchAlinanMesaj := fonksiyonum(pwchGonderilecekMesaj);
Edit1.Text := WideCharToString(pwchAlinanMesaj);
end;
end;
But the problem is Edit1
does not respond when clicking the button.
So, what should I do?