Created
February 8, 2018 07:00
-
-
Save hsienwei/4adc8bab1b97dd1616f7b6ec47aeba00 to your computer and use it in GitHub Desktop.
第二種作法, 將結構傳入c++中memcpy填值, 該作法Data在c#中一定要是struct不能為class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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