[Mono-list] DllImport ... help (gethostname)
Stewart Allen
mono@neuron.com
Sat, 15 Jun 2002 03:26:52 -0400
I did find an example here:
http://www.c-sharpcenter.com/Tutorial/UnManaged.htm
which recommends this structure:
[DllImport("Advapi32.dll", EntryPoint="GetUserName", ExactSpelling=false,
SetLastError=true)]
static extern bool GetUserName(
[MarshalAs(UnmanagedType.LPArray)] byte[] lpBuffer,
[MarshalAs(UnmanagedType.LPArray)] Int32[] nSize );
so I tried this:
static extern int gethostname([MarshalAs(UnmanagedType.LPArray)]
byte[] buf, int len);
but that fails to compile (mcs under linux) with:
** (process:9763): WARNING **: unhandled exception
System.NotImplementedException: "The requested feature is not yet
implemented"
in <0x00032>
System.Reflection.Emit.UnmanagedMarshal:DefineUnmanagedMarshal
(System.Runtime.InteropServices.UnmanagedType)
in <0x005df> Mono.CSharp.Attribute:ApplyAttributes
(Mono.CSharp.EmitContext,object,object,Mono.CSharp.Attributes,Mono.CSharp.Location)
in <0x00220> Mono.CSharp.MethodCore:LabelParameters
(Mono.CSharp.EmitContext,System.Type[],System.Reflection.MethodBase)
in <0x00132> Mono.CSharp.Method:Emit (Mono.CSharp.TypeContainer)
in <0x001df> Mono.CSharp.TypeContainer:Emit ()
in <0x004ca> Mono.CSharp.RootContext:EmitCode ()
in <0x01cbb> Mono.CSharp.Driver:MainDriver (string[])
in <0x00009> Mono.CSharp.Driver:Main (string[])
so I guess this either isn't possible with mono in it's current state or
I need to find an alternate method.
any/all suggestions heartily welcomed.
thanks,
stewart
Stewart Allen wrote:
> I've been struggling with DllImport all evening just to call
> gethostname(char *buf, int len). Seems like it should be simple. There
> appear to be a lot of examples of sending string arguments and getting
> string return values, but I can't find anything that addresses filling a
> preallocated string buffer.
>
> most tests (that I can get to compile) result in:
>
> ** (process:7): WARNING **: unhandled exception
> System.NullReferenceException: "A null value was found where an object
> instance was required"
>
> Any help is greatly appreciated.