Declaration of smiOCTETS And SnmpStrToContext

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I'm trying to implements snmp stuff into my App and I have problems with
SnmpStrToContext to do his job.

I Declared :
[DllImport("Wsnmp32")]
private static extern IntPtr SnmpStrToContext(
IntPtr session,
ref psmiOCTETS ptrsmiOCTETS);

with
struct psmiOCTETS
{
public long len;
public IntPtr ptr;
}

or
[DllImport("Wsnmp32")]
private static extern IntPtr SnmpStrToContext(
IntPtr session,
ref tabCsmiOCTETS smiOCTETS);

with
struct tabCsmiOCTETS
{
public long len;
public char[] ptr;
}

But nothing, I always have an SNMPAPI_CONTEXT_INVALID Error.

I use "public" or "public\0" string as context.

Thanks for help.
 
Cedric,

The declaration for your smiOCTETS structure is incorrect. The len
field should be of type int. A long in .NET is 64 bits, not 32.

Also, you should not use the second declaration of the structure with
the character array. Arrays in structures that are referenced can not be
marshaled correctly, and require manual marshaling.

Hope this helps.
 
Back
Top