0

根据Delphi 到 C++ 类型的映射,Delphi 相当于.wchar_t*PWideChar

DLL 头文件:

#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 文件:

#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;
}

德尔福代码:

//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;

但问题是Edit1单击按钮时没有响应。

所以我该怎么做?

4

0 回答 0