473,471 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

netCfgLock.AcquireWriteLock()

The statement of netCfgLock.AcquireWriteLock(ms, desc1, desc2) gives me an
error saying "Object reference not set to an instance of an object." However,
if I comment this line out, line 2 and line 3 both can be executed
successfully. So I think the problem is those three paramenters of ms, desc1,
and desc2. The following is from Microsoft,

HRESULT AcquireWriteLock(IN DWORD cmsTimeout, IN LPCWSTR
pszwClientDescription, OUT LPWSTR *ppszwClientDescription);

I think that the third parameter should be a pointer to string string, but
how can I pass in a pointer to string in C#?

Thanks for you help. (following is the code)


[Guid("C0E8AE9F-306E-11D1-AACF-00805FC1270E"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
[ComVisible(true)]
interface INetCfgLock
{
int AcquireWriteLock([In, MarshalAs(UnmanagedType.I8)] ulong
cmsTimeout,
[In, MarshalAs(UnmanagedType.LPWStr)] string pszwClientDescription,
[Out, MarshalAs(UnmanagedType.LPWStr)] string ppszwClientDescription);
int ReleaseWriteLock();
int IsWriteLocked([Out, MarshalAs(UnmanagedType.LPWStr)] string
ppszwClientDescription);
};

object objINetCfgLock = null;
int _nRet = 0;
_nRet = Ole32Methods.CoCreateInstance(ref INetCfg_Guid.CLSID_CNetCfg,
null, Ole32Methods.CLSCTX_INPROC_SERVER, ref
INetCfg_Guid.IID_INetCfgLockClass, out objINetCfgLock);
objINetCfgLock.GetType();
INetCfgLock netCfgLock = objINetCfgLock as INetCfgLock;
if (netCfgLock != null)
{
ulong ms = 500;
string desc1 = "NETCONN";
string desc2 = string.Empty;
netCfgLock.AcquireWriteLock(ms, desc1, desc2); //Line 1
netCfgLock.ReleaseWriteLock(); //Line 2
_nRet = netCfgLock.IsWriteLocked(desc1); //Line 3
}

Oct 22 '08 #1
0 895

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.