Skip to content

Instantly share code, notes, and snippets.

@hsienwei
Created February 8, 2018 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsienwei/4e2c19d03f1bf78303dce99fb32aceec to your computer and use it in GitHub Desktop.
Save hsienwei/4e2c19d03f1bf78303dce99fb32aceec to your computer and use it in GitHub Desktop.
第三種作法, 只用IntPtr做參照, 要取值再個別呼叫
PLUGIN_DLL_API const Data* GamePlayer_GetBattleReportBaseInfo(const uint32 mail_id) { ... }
PLUGIN_DLL_API uint32 Repo_ReportID(Data *Dta) { return Dta->id; }
PLUGIN_DLL_API uint32 Repo_ReportTime(Data *Dta) { return Dta->time; }
PLUGIN_DLL_API uint16 Repo_Type(Data *Dta) { return Dta->type; }
public abstract class ReportBase //ReportHandle : ReportBase
{
#region DllImport
[DllImport(SysPluginBase.PlatformDllName)]
private static extern UInt32 Repo_ReportID(HandleRef Dta);
[DllImport(SysPluginBase.PlatformDllName)]
private static extern UInt32 Repo_ReportTime(HandleRef Dta);
[DllImport(SysPluginBase.PlatformDllName)]
private static extern UInt16 Repo_Type(HandleRef Dta);
#endregion
bool IsSetted = false;
protected HandleRef _handle;
public ReportBase(IntPtr Ptr)
{
if (Ptr == System.IntPtr.Zero)
return;
_handle = new HandleRef(this, Ptr);
IsSetted = true;
}
#region api
public UInt32 ID { get { return (IsSetted) ? Repo_ReportID(_handle) : 0; } }
public UInt32 Time { get { return (IsSetted) ? Repo_ReportTime(_handle) : 0; } }
public UInt16 Type { get { return (IsSetted) ? Repo_Type(_handle) : 0; } }
#endregion
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment