IntPtr.Zero to PVOID - Invalid pointer
- From: Jeff Van Epps <jve86@xxxxxxxxxxx>
- Date: Fri, 10 Aug 2007 13:34:43 -0700
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().
.
- Follow-Ups:
- Re: IntPtr.Zero to PVOID - Invalid pointer
- From: Jeff Van Epps
- Re: IntPtr.Zero to PVOID - Invalid pointer
- Prev by Date: Instantiating an Excel Worksheet
- Next by Date: WebBrowser and PDF
- Previous by thread: Instantiating an Excel Worksheet
- Next by thread: Re: IntPtr.Zero to PVOID - Invalid pointer
- Index(es):
Relevant Pages
|