I have a function in C++ that returns pointer values:
fPosFirst( int &aId, char *aNname, char *aDirectory );
My syntax in c# is:
fPosFirst(ref int aId, String aNname, String aDirectory);
the function returns the id but not the string parameters that anyone knows?
Assuming that the native function does not "return pointers" but writes characters to the memory locations specified by aNname and aDirectory, you should be able to pass a StringBuilder with a proper capacity to the native function:
void fPosFirst(ref int aId, StringBuilder aNname, StringBuilder aDirectory);
Usage:
var aId = 0;
var aNname = new StringBuilder(260);
var aDirectory = new StringBuilder(260);
fPosFirst(ref aId, aNname, aDirectory);
如果要在方法内分配给它们,并使这些值在方法外可用out
则需要使字符串参数为ref
或out
。
You need to use out
keyword before parameters names ( example ). But actually this is not good practice in C#
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.