using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace PatternSequencer
{
class Version
{
public string majorVersion;
public string minorVersion;
ushort* pmajorVersion;
ushort* pminorVersion;
ulong status;
[DllImport(@"c:\DOcuments\Myapp.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SRX_DllVersion")]
public static extern ulong SRX_DllVersion(ushort* pmajorVersion, ushort* pminorVersion);
public Version()
{
status = SRX_DllVersion(&pmajorVersion, &pminorVersion);
if (status)
{
majorVersion = "1 - " + *pmajorVersion;
minorVersion = "1 - " + *pminorVersion;
}
else
{
majorVersion = "0 - " + *pmajorVersion;
minorVersion = "0 - " + *pminorVersion;
}
}
}
}
它引發錯誤指針和固定大小的緩衝區只能用於不安全的上下文中。我如何將指針傳遞給C++ dll?我是新來的C#,請幫我如何訪問以指針作爲C#輸入參數的C++函數
聲明參數爲'ref',這將消除對'不安全'代碼的需要。 – William
@William:請你詳細解釋一下。我是新來的C# – user2495173
你想在這裏做什麼被稱爲[Marshaling](http://msdn.microsoft.com/en-us/magazine/cc164193.aspx)。這是一個很大的話題,但對於這樣的簡單案例來說,這並不難。 –