//c++的结构
typedef struct req_submit_job_msg {
/* job resource description */
uint32_t nprocs; /* -n: number of tasks */
uint32_t nprocs_set; /* 1:  if nprocs is set */
uint32_t min_nodes; /* -N: the minimum number of required nodes */
uint32_t nodes_set; /* 1: if min_nodes is set */
uint32_t tlimit; /* -t: expected job time */
uint32_t tlimit_set; /* 1: if tlimit is set */
char * partition;  /* -p: partition name to submit job */
char * req_nodes;  /* -w: list of required nodes */
char * exc_nodes;  /* -x: list of excluded nodes */ /* application description */
uint32_t argc; /* number of args */
char ** argv; /* arrays of args */
uint32_t envc; /* number of env array */
char ** env; /* array of env elements */
char * work_dir; /* task working dir */ /* misc */
uint32_t job_type; /* YHMPI, LS_DYNA, FLUENT etc */
uint32_t job_acct_req;  /* 1: job acct required. Omitted by now */
} req_submit_job_msg_t;//C#下的结构
public  struct req_submit_job_msg_t
        {
          [MarshalAs(UnmanagedType.U4)]  
            public uint nprocs;
           [MarshalAs(UnmanagedType.U4)]  
            public uint nprocs_set;
          [MarshalAs(UnmanagedType.U4)]  
            public uint min_nodes;
          [MarshalAs(UnmanagedType.U4)]  
            public uint nodes_set;
           [MarshalAs(UnmanagedType.U4)]  
            public uint tlimit;
          [MarshalAs(UnmanagedType.U4)]  
            public uint tlimit_set;
           [MarshalAs(UnmanagedType.LPStr)]
            public string partition; //
          [MarshalAs(UnmanagedType.LPStr)]
            public string req_nodes; //
           [MarshalAs(UnmanagedType.LPStr)]
            public string exc_nodes; //
          [MarshalAs(UnmanagedType.U4)] 
            public uint argc;
           [MarshalAs(UnmanagedType.ByValArray)]
            public string[] argv;  //
          [MarshalAs(UnmanagedType.U4)]  
            public uint envc;
          [MarshalAs(UnmanagedType.ByValArray)]
            public string[] env;   //
          [MarshalAs(UnmanagedType.LPStr)]
            public string work_dir; //
           [MarshalAs(UnmanagedType.U4)] 
            public uint job_type;
          [MarshalAs(UnmanagedType.U4)] 
            public uint job_acct_req;
        }
        [StructLayout(LayoutKind.Sequential)]
        public  struct resp_submit_job_msg_t
        {
           [MarshalAs(UnmanagedType.U4)] 
            public uint job_id;
        }//调用动态链接库
 [DllImport(@"YhrceDll.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  unsafe  public static extern int yhrce_submit_job(int sess_id,  IntPtr req, ref IntPtr rep);//在函数中调用
private void simpleButton7_Click(object sender, EventArgs e)
{
 try
                {
                    req_submit_job_msg_t req_submit=new req_submit_job_msg_t();
                    req_submit.nprocs = 2;
                    req_submit.nprocs_set = 1;
                    req_submit.min_nodes = 2;
                    req_submit.nodes_set = 1;
                    req_submit.tlimit = 7200;  //minutes 
                    req_submit.tlimit_set = 1;
                    req_submit.partition ="X";
                    req_submit.job_type = 5;
                    req_submit.argc = 1;
                    req_submit.work_dir = "//vol5//home//chenhf15//";                    
                    req_submit.argv = new string[req_submit.argc];
                    req_submit.argv[0] = "//vol5//home//chenhf15//yhrce_test//stest"; //executable name 
                    req_submit.envc = 0;
                    req_submit.env = new string[1];
                    req_submit.env[0] = "qiuxiaopengTest";
                    req_submit.job_type = 0;
                    req_submit.job_acct_req = 1;
                    req_submit.req_nodes = "3";
                   int rc = 0;                   
                   IntPtr ptr1 = Marshal.AllocHGlobal(Marshal.SizeOf(req_submit));
                   Marshal.StructureToPtr(req_submit, ptr1, false);                     resp_submit_job_msg_t s = new resp_submit_job_msg_t();
                   IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(s));
                   Marshal.StructureToPtr(s, ptr, false);
                   rc = yhrce_submit_job(sess_id, ptr1, ref  ptr);//调用出现问题
     }     catch (Exception ex)
        {
           string str = ex.Message; //问题是尝试读取或写入受保护的内存,这通常指示其他内存已损坏?
        }}