I want to be a C ++ DLL for C # call and return list, type is a structure defined
c ++ The structure is;
struct mailInfo
{
const char *mailFrom;
const char *mailReceivers;
const char *mailDate;
const char *mailTitle;
const char *mailBody;
}
;
C ++ code is:
extern "C" __declspec(dllexport) vector<mailInfo> rData(char module_path[],char tableName[])
{
mailInfo mailIo;
int result = sqlite3_open(((string)module_path+"\\mail.db").c_str(), &conn);
if (!result)
{
sqlite3_stmt *stat;
const char *pzTail = NULL;
sqlcommand="select * from "+(string)tableName+";";
sqlite3_prepare(conn, sqlcommand.c_str(), -1, &stat, &pzTail);
int nColumn = sqlite3_column_count(stat);
result = sqlite3_step(stat);
while (result == SQLITE_ROW)
{
mailIo= outputItem(stat, nColumn, module_path);
mInfoList.push_back(mailIo);
cout << endl;
result = sqlite3_step(stat);
}
return mInfoList;
}
The structure is defined in C #:
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct mailInfo
{
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)]
public byte[] mailFrom;
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)]
public byte[] mailReceivers;
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)]
public byte[] mailDate;
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)]
public byte[] mailTitle;
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)]
public byte[] mailBody;
}
[DllImport("my.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
public static extern List<mailInfo> rData(byte[] dbPath, byte[] TBFullName);
Code C # call is;
List<loadDLL.mailInfo> ml = new List<loadDLL.mailInfo>();
byte[] bTN = Encoding.Default.GetBytes(TN);
byte[] bdbPath = Encoding.Default.GetBytes(Form1.datePath + emailFromAddress);
loadDLL.rData(bdbPath, bTN);
But when I run debug, the following tips:
Unable to marshal "return value": unable to marshal the generic type.
I wonder how to return list data from C ++, thank you!