typedefstruct tag FCSDKSTRUCT{
WORD funcno;
char foldername[11];
WORD totalindex;
char indextitle[12][31];
char indexvalue[12][31];
WORD autonext;
char errormsg[80];
} FCSDKSTRUCT;
//prototype
int FCSDKAPI(FCSDKSTRUCT* pfcsdkstruct);
into a C# program.
Here is my code
namespace DocMgrP01
{
/// <summary>
/// Summary description for Form1.
/// </summary>
///
public class FrmDocSearch :
System.Windows.Forms.Form
{
[StructLayout(LayoutKind.Sequential)]
// public struct FCSDKSTRUCT
public class FCSDKSTRUCT
{
public short FuncNo;
[MarshalAs
(UnmanagedType.ByValTStr, SizeConst = 11)]
public string FolderName;
public short TotalIndex;
// [MarshalAs
(UnmanagedType.LPArray , SizeParamIndex = 12, SizeConst =
31)]
[MarshalAs
(UnmanagedType.LPArray , SizeConst = 372)]
public char[,] IndexTitle;
// [MarshalAs
(UnmanagedType.LPArray , SizeParamIndex = 12, SizeConst =
31)]
[MarshalAs
(UnmanagedType.LPArray , SizeConst = 372)]
public char[,] IndexValue;
public short AutoNext;
[MarshalAs
(UnmanagedType.ByValTStr, SizeConst = 80)]
public string ErrorMessage;
}
[DllImport(@"C:\Program
Files\Resolutions\RFileMgr\Client\Program\fcsdkdll.dll",
CharSet = CharSet.Unicode)]
// [DllImport("fcsdkdll.dll", CharSet =
CharSet.Auto)]
public static extern int FCSDKAPI
(FCSDKSTRUCT pfcsdkstruct);
private System.Windows.Forms.TextBox
textSSN;
private System.Windows.Forms.TextBox
textLName;
private System.Windows.Forms.TextBox
textFName;
private System.Windows.Forms.TextBox
textMName;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button
btnSearch;
private System.Windows.Forms.Button
btnCancel;
private System.Windows.Forms.Label label5;
private
System.Windows.Forms.CheckedListBox chklstDocType;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container
components = null;
public FrmDocSearch()
{
//
// Required for Windows Form
Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code
after InitializeComponent call
//
FCSDKSTRUCT ss = new FCSDKSTRUCT
();
ss.IndexTitle = new char[12,31];
ss.IndexValue = new char[12,31];
ss.FuncNo = 1;
ss.FolderName = "HRTEST";
// ss.IndexTitle[0,0] = "SSN";
// ss.IndexTitle[0,1] = "LAST NAME";
// ss.IndexTitle[0,2] = "FIRST NAME";
// ss.IndexTitle[0,3] = "MIDDLE
NAME";
// ss.IndexTitle[0,4] = "DOCTYPE";
ss.IndexTitle[0,0] = 'S';
ss.IndexTitle[0,1] = 'S';
ss.IndexTitle[0,2] = 'N';
// for(int i=5;i<12;i++)
// {
// ss.IndexTitle[i] = "";
// }
// ss.IndexValue[00] = "439-43-0675";
// ss.IndexValue[01] = "WILLIAMS";
// ss.IndexValue[02] = "NATASHA";
// ss.IndexValue[03] = "D";
// ss.IndexValue[04] = "I-9";
ss.IndexValue[0,0] = '4';
ss.IndexValue[0,1] = '9';
ss.IndexValue[0,2] = '3';
// for(int i=5;i<12;i++)
// {
// ss.IndexValue[i] = "";
// }
// ss.AutoNext = 1;
ss.ErrorMessage = "";
int sdkrt = FCSDKAPI(ss);
if (sdkrt != 0)
{
MessageBox.Show
(ss.ErrorMessage.ToString(),"Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
Thank you.
The struct parameter should have the ref modifier applied to it.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
[DllImport("fcsdkdll.dll")]
public static extern int FCSDKAPI(ref FCSDKSTRUCT pfcsdkstruct);
...
int sdkrt = FCSDKAPI(ref ss);
Another Question how do i Marshall
char indextitle[12][31];
char indexvalue[12][31];
>-----Original Message-----
>
>>How to define and call it in the program
>
>[DllImport("fcsdkdll.dll")]
>public static extern int FCSDKAPI(ref FCSDKSTRUCT
pfcsdkstruct);
>
>....
>
>int sdkrt = FCSDKAPI(ref ss);
>
>
>
>Mattias
>
>--
>Mattias Sjögren [MVP] mattias @ mvps.org
>http://www.msjogren.net/dotnet/ |
http://www.dotnetinterop.com
>Please reply only to the newsgroup.
>.
>
What you had was almost correct, just change LPArray yo ByValArray
[MarshalAs(UnmanagedType.ByValArray , SizeConst = 372)]
public char[] IndexValue;