一位朋友,.NET(C#)DLL問我寫在C#中的DLL文件Delphi應用程序。他想使用這個函數decleration與它溝通:寫作Delphi應用程序
function OpenAddOnFile(const mafCode: PWideChar; const mafFilePath: PWideChar;
const mafVersion: PWideChar): Pointer; stdcall;
我遇到的問題是它翻譯成C#。可等PWideChar心不是...我已經嘗試過這樣的:
public Pointer OpenAddOnFile(
[MarshalAs(UnmanagedType.LPWStr)]string mafcode,
[MarshalAs(UnmanagedType.LPWStr)]string maffilepath,
[MarshalAs(UnmanagedType.LPWStr)]string mafversion
)
但它不工作現在:)
進一步我怎麼能在C#中返回一個指針,以我的形式?
有人可以幫我嗎? 在此先感謝!
編輯:\
他給了我這個額外的代碼: 我問他對於函數調用,他給了我一個信息:
unit unAddOn;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.ComCtrls;
function LoadAddOnFile(aPath: String; aVersion: String; var aFilePath: String;
var aCode: String): Boolean;
const
AddOnExt: String = '.maf';
implementation
function LoadAddOnFile(aPath: String; aVersion: String; var aFilePath: String;
var aCode: String): Boolean;
type
TOpenAddOnFile = function(const mafCode: PWideChar; const mafFilePath: PWideChar;
const mafVersion: PWideChar): Pointer; stdcall;
TCloseAddOnFile = procedure(var mafCode: PWideChar; var mafFilePath: PWideChar;
var mafQuitPopUp: PWideChar); stdcall;
var
CloseAddOnFile: TCloseAddOnFile;
OpenAddOnFile: TOpenAddOnFile;
AddOnMainForm: TForm;
AddOnHandle: THandle;
mafQuitPopUp: PWideChar;
mafFilePath: PWideChar;
mafVersion: PWideChar;
mafCode: PWideChar;
begin
Result := True;
mafQuitPopUp := PWideChar(EmptyStr);
mafFilePath := PWideChar(aFilePath);
mafCode := PWideChar(aCode);
mafVersion := PWideChar(aVersion);
try
AddOnHandle := LoadLibrary(PWideChar(aPath));
if (AddOnHandle <> 0) then
begin
@OpenAddOnFile := GetProcAddress(AddOnHandle, 'OpenAddOnFile');
@CloseAddOnFile := GetProcAddress(AddOnHandle, 'CloseAddOnFile');
if (@OpenAddOnFile <> nil) then
begin
AddOnMainForm := OpenAddOnFile(mafCode, mafFilePath, mafVersion);
AddOnMainForm.Position := poScreenCenter;
AddOnMainForm.ShowModal;
if (@CloseAddOnFile <> nil) then
begin
CloseAddOnFile(mafCode, mafFilePath, mafQuitPopUp);
end;
FreeAndNil(AddOnMainForm);
Application.ProcessMessages;
end;
end;
if not (mafQuitPopUp = PWideChar(EmptyStr)) then
begin
ShowMessage(mafQuitPopUp);
end;
aFilePath := String(mafFilePath);
aCode := String(mafCode);
except
Result := False;
end;
end;
end.
是,你可以在C# – 2013-05-13 15:48:47
返回一個指針那麼,你是如何加載德爾福一個C#DLL。它是原生的Win32 Delphi還是Delphi.net?而C#中沒有'指針'。有'IntPtr'。什麼是回報價值?什麼是C#應用程序意味着返回?參數指向可修改的緩衝區嗎?基本上你的問題完全缺乏需要回答的細節。 – 2013-05-13 15:48:59
還有另一個問題。什麼「它不工作的意思」?你的開發工具爲你提供包含詳細信息的錯誤消息。你爲什麼不傳遞這些信息。你想讓我們很難嗎?! – 2013-05-13 15:54:58