IntPtr.Zero to PVOID - Invalid pointer

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I'm trying to gain access to netcfgx.dll from C# in order to tweak
network bindings and so forth. I'm stuck at the point where I am
calling INetCfg.Initialize() -- everything I try either returns a
NullReferenceException with "Invalid pointer", or fails to compile.

The signature of this COM method is documented as
HRESULT Initialize(IN PVOID pvReserved);

The Interop declaration looks like this
void Initialize([In] IntPtr pvReserved);

There are two VC++ programs which work with netcfgx, bindview in the
DDK, and a third party program IBindCfg.exe. Both pass
Initialize(NULL), where NULL is #defined as 0. They work correctly.
Everything I find tells me that I should be passing
Initialize(IntPtr.Zero), but that results in "Invalid pointer". I
can't see any way to tell whether the error is coming from the
Initialize() code or from something Interop is doing before/after.

I've tried various ways of changing the declaration and what I pass
it, just trying to get a 0 across to the other side somehow, using
"int", "void *", "object", "object *", various "unsafe" pointer ideas,
but I've never had anything work.

Any advice?

The way that I got the declaration in the first place was a bit of a
journey as well. Take netcfgx.idl from the DDK, remove the cpp_quote
lines, add a library section and coclass section, midl it, run tlbimp,
then run Reflector on the DLL to get back the C#. Well, it seemed like
that would be easier than trying to code all the declarations by hand.
(It looks like if I ever get Initialize() to work I'll have to also
muck with the declarations for the GUID parameters since the compiler
believes the MIDL structure GUID is different from the C# type Guid.)
Trying to use the whole set of recovered C# gives me
ExecutionEngineException on first use, so I wound up having to pick
individual pieces of it at a time - I'm getting further that way,
which doesn't make much sense to me as all I've effectively done is to
remove declarations for interfaces which I'm not even calling. I can
now instantiate and call AcquireWriteLock() with no problem. But I
can't Initialize().

.



Relevant Pages

  • Re: Function Argument Problem
    ... It works when calling other functions from the same object. ... >> Dim strCategory As String ... it's the declaration that is the problem. ...
    (microsoft.public.vb.general.discussion)
  • Re: Pointer to an array of pointers
    ... Be very careful when using this function declaration since you don't know whether you're calling the ASCII or Unicode ... > Yes, i tried the Mike solution, but it is crashing VB6. ...
    (microsoft.public.vb.general.discussion)
  • Re: Application crashing because of chkesp.c error..
    ... A calling convention is the protocol used to call the function (how ... You may have a bad declaration of the function you are calling. ... > client machine.. ...
    (microsoft.public.vc.mfc)
  • Re: Error on Exit Sub
    ... MacDermott wrote: ... > I've just been debugging some code which was throwing an "object variable or ... Please show us the declaration line of the called Sub, ... along with the declarations of all terms in that calling line. ...
    (microsoft.public.vb.general.discussion)
  • Re: float to Money cast
    ... data type doesn't offer that, it gets a lot more complicated. ... You think specifying length and index in the declarations is more ... complicated than calling Math.Round on the expressions. ... precision/scale as part of a type declaration. ...
    (microsoft.public.dotnet.languages.csharp)