int to proc conversion

  • Thread starter Thread starter Dan Pavel
  • Start date Start date
D

Dan Pavel

Hi,

I am using a conversion from int to char to use it with SNMP.
In this moment I use:

int proc=45; // here cam be any value from 1 to 255
string cProc="";
cProc+=Convert.ToChar(proc);
mib_write(computer,oid,new Universal(cProc));

but the problem is when I use proc value between 127 to 159, the cProc
values are all the same -> ""

I changed to:

[StructLayout(LayoutKind.Explicit)]
struct IntToCharCast
{
[FieldOffset(0)]
public int i;
[FieldOffset(0)]
public char f;
};
IntToCharCast caster;

int iProc=45;// here cam be any value from 1 to 255
char cProc;
caster.i = iProc;
cProc=caster.f;
mib_write(computer,oid,new Universal(cProc));

and I get the same values.

What I am doing wrong ?

Thank you,
Dan
 
Dan,

Have you considered using one of the encodings to convert the value?

Also, are you sure your structure should have a char value in it?
Unless you are using unicode characters (possible, but I don't see many
implementations with functions exported from DLLs that take the time to use
unicode).

Hope this helps.
 
Dan Pavel said:
I am using a conversion from int to char to use it with SNMP.
In this moment I use:

int proc=45; // here cam be any value from 1 to 255
string cProc="";
cProc+=Convert.ToChar(proc);
mib_write(computer,oid,new Universal(cProc));

but the problem is when I use proc value between 127 to 159, the cProc
values are all the same -> ""

I very much doubt that they're actually the same - they're *different*
unprintable characters. This is correct, as Unicode 128-159 are indeed
unprintable. What did you expect to see?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top