Skip to content

Instantly share code, notes, and snippets.

@hsienwei
Created February 8, 2018 07:00
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/4adc8bab1b97dd1616f7b6ec47aeba00 to your computer and use it in GitHub Desktop.
Save hsienwei/4adc8bab1b97dd1616f7b6ec47aeba00 to your computer and use it in GitHub Desktop.
第二種作法, 將結構傳入c++中memcpy填值, 該作法Data在c#中一定要是struct不能為class
PLUGIN_DLL_API bool GetDataRef(const int data_id,
Data* ref)
{
const go3::BuildDataPN* report = go3::BuildDataTable3::Instance().GetTableData(data_id);
if (NULL == report)
{
return NULL;
}
size_t TargetSize = sizeof(*ref);
size_t SourceSize = sizeof(*report);
if (TargetSize == SourceSize)
{
memcpy(ref, report, TargetSize);
}
else
{
memset(ref, 1, TargetSize);
}
return true;
}
[DllImport(SysPluginBase.PlatformDllName)]
private static extern bool GetDataRef(int id, ref Data Dta);
public Data GetData(int id)
{
Data Dta = new Data();
bool IsSuccess = false;
IsSuccess = GetDataRef(id, ref Dta);
if(IsSuccess)
return Dta;
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment