I'm new in programming, Can someone help me call a pointer function from a delphi dll into Visual C# function.
Here is the Delphi Function stored into the DLL. // Delphi Code Stored in the DLL
function DeviceName(Size : Integer; Msg : Pointer) : Integer stdcall;
var
i: Integer;
TempByte : PByte;
TempName : string;
begin
if DLLClass.DevList.HidDevices.Count > 0 then
begin
TempName := (DLLClass.DevList.HidDevices.Name[DLLClass.HIDTool.CurrentDeviceIndex]);
if Length(TempName) <= Size then
begin
try
TempByte := Msg;
for i := 0 to Length(TempName) - 1 do
begin
TempByte^ := Ord(TempName[i+1]);
Inc(TempByte)
end;
Result := Length(TempName);
except
Result := -2;
end;
end
else
begin
Result := -3;
end;
end
else
begin
Result := -1;
end;
end;
//C# Code ` //Import a Function Pointer
[DllImport("HID_DLL.dll", CallingConvention= CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public unsafe static extern int DeviceName(IntPtr Size, [MarshalAs(UnmanagedType.LPStr)] string Msg);
unsafe static void Main()
{
byte[] buffer = new byte[32768];
DeviceName(255, &**buffer);
Console.WriteLine("%s\n" + buffer);
}
`