111,105
社区成员




else if (btn.Name == "PackBtn")
{
int PacFileLength = 0;
ST_FILENAME_PACK[] stFilePacList = new ST_FILENAME_PACK[3];
stFilePacList[0].sSrcFileName = System.Text.Encoding.Default.GetBytes(TextBox5.Text);
stFilePacList[0].sDstFolderPath = System.Text.Encoding.Default.GetBytes("E:\\Temp\\t3");
stFilePacList[1].sSrcFileName = System.Text.Encoding.Default.GetBytes(TextBox6.Text);
stFilePacList[1].sDstFolderPath = System.Text.Encoding.Default.GetBytes("E:\\Temp");
stFilePacList[2].sSrcFileName = System.Text.Encoding.Default.GetBytes(TextBox7.Text);
stFilePacList[2].sDstFolderPath = System.Text.Encoding.Default.GetBytes("E:\\Temp\\t3");
string PacName = TextBox8.Text;
if ( ( PacFileLength = DoPack2(ref stFilePacList, 3, PacName, 1) ) < 0 )
{
MessageBox.Show("DoPack Error");
}
}
public struct ST_FILENAME_PACK
{
public byte[] sSrcFileName;
public byte[] sDstFolderPath;
}
#define MAX_PATH 260
typedef struct
{
char sSrcFileName[MAX_PATH];
char sDstFolderPath[MAX_PATH];
} ST_FILENAME_PACK;
int DoPack2(ST_FILENAME_PACK *pstFilenamePackList, int nSrcFileNameNumber, char *pPackFileName, int nPackSubFoderFlag);
public extern static int DoPack2(ref ST_FILENAME_PACK[] pstFilenamePackList, int nSrcFileNameNumber, string pPackFileName, int nPackSubFoderFlag);
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct ST_FILENAME_PACK
{
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 260)]
public string sSrcFileName;
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 260)]
public string sDstFolderPath;
}
函数DoUnpack2在C#中的声明:
[DllImport("xxxx.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public extern static int DoPack2([In, Out] ST_FILENAME_PACK[] pstFilenamePackList, int nSrcFileNameNumber, string pPackFileName, int nPackSubFoderFlag);
变量stFilePacList的赋值过程和DoPack2的传参过程如下:
int PacFileLength = 0;
ST_FILENAME_PACK[] stFilePacList = new ST_FILENAME_PACK[3];
stFilePacList[0].sSrcFileName = TextBox5.Text;
stFilePacList[0].sDstFolderPath = "E:\\Temp\\t3";
stFilePacList[1].sSrcFileName = TextBox6.Text;
stFilePacList[1].sDstFolderPath = "E:\\Temp\\t3";
stFilePacList[2].sSrcFileName = TextBox7.Text;
stFilePacList[2].sDstFolderPath = "E:\\Temp\\t3";
string PacName = TextBox8.Text;
if ( ( PacFileLength = DoPack2( stFilePacList, 3, PacName, 1) ) < 0 )
{
MessageBox.Show("DoPack Error");
}