Link to home
Start Free TrialLog in
Avatar of OctaviaIS
OctaviaIS

asked on

C# String Pointers - AsnOctetString.str

Hi all,

I have played around with the code at [http://www.righto.com/pc/snmp.html] to get values from an SNMP device.  At the moment that seems to be working OK.

My problem comes in attempting to update the device. The code sample came with a SNMPset method that can update an integer value on the device. I need to update integers and octstrings. I've modified the code from :

      asnValue.asnType = ASN_INTEGER;
      asnValue.asnValue.number = value;

To :

      asnValue.asnType = ASN_OCTETSTRING;
      asnValue.asnValue.str = value;

However the .str data type is AsnOctetString. The number data type was integer so I could just supply this a int variable.

There is no Text property of the AsnOctetString only a stream which is a IntPtr. I guess I need to set this to the pointer of the string that has the data I want to send to the device.

How can I do this? I've tried the fixed statement but I get compiler errors with the following code :

    AsnOctetString asnOctetString = new AsnOctetString();
    string setValue = "Sample String Value" ;

    fixed( char* p = setValue )
    {
        asnOctetString.stream = p ;
    }

    asnValue.asnValue.str = asnOctetString;

Points will be awarded to the person who crack this, perhaps extra points for someone who can give the a polished method!
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of OctaviaIS
OctaviaIS

ASKER

Thanks chaps,

I hope the split of points is fair to you both!