c++ - convert structure to char pointer in c# -


below piece of code written in c++, how can convert in c#. if check pams_get_msgw function , first param of (char*), how can pass same in c# .

                struct                  {                     short m_nstatus;                     short m_nreg_id;                     short m_nnumber_reg;                 } oregreply;                  short nbufsize = sizeof(oregreply);                 q_address   osenderqueue;                 nmsgtype = msg_type_sbs_reg_reply;                 cpriority = 0;                 ltimeout = 300; // 30 seconds                  //wait reply telegram sbs server                 lstatus = pams_get_msgw((char *) &oregreply, &cpriority, &osenderqueue,                                         &nmsgclass, &nmsgtype, &nbufsize, &nmsglen,                                         &ltimeout, null, null, null, null,                                          null, null, null); 

my c# declaration pams_get_msgw function this

  [dllimport("dmqcl32.dll")]   public static extern int pams_get_msgw(stringbuilder msg_area, string priority, out q_address source,                                                out short clas, out short type,                                                ref short msg_area_len, out short len_data, ref int timeout,                                                ref int sel_filter, out psb psb, out showbuffer show_buffer,                                                ref int show_buffer_len, ref int large_area_len, out int large_size,                                                [marshalas(unmanagedtype.lpstr)] string nullarg_3); 

and actual c++ declaration

typedef long (callback* pamsgetmsgw)(char *,char *,q_address *, short *, short *, short *,                                      short *, long *, long *, struct psb *,                                        struct show_buffer *, long *, char *, char *, char * ); 

how can pass structure first argument, way doing in c++ ?

you should able declare struct in c# class rather struct, , can pass via p/invoke without using ref keyword.

what's happening c code ancient it's using char* should using byte*.

anyway, default marshaling p/invoke handles pinning , passing object references cases, work if pass class object. (many c++ structs can declared classes @ c# side can make p/invoke easier.)

you don't show c declaration pams_get_msgw() looks must use marshal.sizeof(regreply) value of msg_area_len (where regreply c# class c's oregreply struct).

btw: need assistance declaring c# version of oregreply struct?


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -