How to receive a BYTE[] from C# -


there 2 questions:

  1. i try make program need use com component(ocx) created mfc. assume component name myocx. myocx has function "readuserdata (byte* buf)".(i can see function spec has become readuserdata(ref byte buf) in c#.) buf byte[30]. content string: 100.

here partial of code:

        byte buf = new byte();         if (myocx.readuserdata(ref buf))         {             (int = 0; < 30; i++)             {                 myocx.readuserdata(ref buf);                 textbox3.text += (char)buf;             }         } 

there no error during running, textbox3.text content "111111111111111111111111111111", think because "100" first letter '1' 30 times.

i ask how write code make can "100" original byte[30];

  1. another question not has readuserdata(byte* buf), has writeuserdata(byte* buf). write "200" buf. please tell me how this.

thank you.

not knowing how myoxc.readuserdata works, try this:

byte[] buf = new byte[30];  if (myocx.readuserdata(ref buf))     (int = 0; < byte.length; i++)        textbox3.text += (char)buf[i]; 

in code looks first read succeeds, and, because supplied single byte write data returned first character '1'. subsequent calls fail, why buf never changed, keep on printing out original value.


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -