Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pointer to a pointer to a struct causes access violation

16 views
Skip to first unread message

alle...@yahoo.com

unread,
May 19, 2015, 6:56:18 PM5/19/15
to
Hi All,

I am having some issues trying to get a struct using a pointer to a pointer to a struct.
The system is a Windows Server 2012 r2, my code and the interop are compiled to 64bit.

The IDL for the sruct and the interface are:

typedef struct _tagCCatConfigInfo {
DWORD dwCCatConfigInfoFlags;
DWORD dwEnable;
DWORD dwCatFlags;
LPSTR pszRoutingType;
LPSTR pszBindDomain;
LPSTR pszUser;
LPSTR pszPassword;
LPSTR pszBindType;
LPSTR pszSchemaType;
LPSTR pszHost;
LPSTR pszNamingContext;
LPSTR pszDefaultDomain;
DWORD dwPort;
ISMTPServer *pISMTPServer;
ICategorizerDomainInfo *pIDomainInfo;
DWORD dwVirtualServerID;
} CCATCONFIGINFO, *PCCATCONFIGINFO;


interface ICategorizerParameters : IUnknown
{
HRESULT GetDSParameterA(
[in] DWORD dwDSParameter,
[out] LPSTR *ppszValue);

HRESULT SetDSParameterA(
[in] DWORD dwDSParameter,
[in, unique] LPCSTR pszValue);

HRESULT RequestAttributeA(
[in, unique] LPCSTR pszName);

HRESULT GetAllAttributes(
[out] LPSTR **prgszAllAttributes);

HRESULT ReserveICatItemPropIds(
[in] DWORD dwNumPropIdsRequested,
[out] DWORD *pdwBeginningPropId);

HRESULT ReserveICatListResolvePropIds(
[in] DWORD dwNumPropIdsRequested,
[out] DWORD *pdwBeginningPropId);

HRESULT GetCCatConfigInfo(
[out] PCCATCONFIGINFO *ppCCatConfigInfo);od
};



The managed counterparts are:

[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct _tagCCatConfigInfo
{
public uint dwCCatConfigInfoFlags;
public uint dwEnable;
public uint dwCatFlags;

[MarshalAs(UnmanagedType.LPStr)]
public string pszRoutingType;

[MarshalAs(UnmanagedType.LPStr)]
public string pszBindDomain;

[MarshalAs(UnmanagedType.LPStr)]
public string pszUser;

[MarshalAs(UnmanagedType.LPStr)]
public string pszPassword;

[MarshalAs(UnmanagedType.LPStr)]
public string pszBindType;

[MarshalAs(UnmanagedType.LPStr)]
public string pszSchemaType;

[MarshalAs(UnmanagedType.LPStr)]
public string pszHost;

[MarshalAs(UnmanagedType.LPStr)]
public string pszNamingContext;

[MarshalAs(UnmanagedType.LPStr)]
public string pszDefaultDomain;

public uint dwPort;

[MarshalAs(UnmanagedType.Interface)]
public ISMTPServer pISMTPServer;

[MarshalAs(UnmanagedType.Interface)]
public ICategorizerDomainInfo pIDomainInfo;

public uint dwVirtualServerID;
}


[ComConversionLoss, Guid("86F9DA7B-EB6E-11D1-9DF3-00C04FA322BA"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[ComImport]
public interface ICategorizerParameters
{
....
....
....

[MethodImpl(MethodImplOptions.InternalCall)]
void GetCCatConfigInfo([Out] ref IntPtr ppCCatConfigInfo);
}


This is my calling code:

void IMailTransportCategorize.ExpandItem(ICategorizerParameters pICatParms, ICategorizerItem pICatItem, IMailTransportNotify pINotify, IntPtr pvNotifyContext)
{
IntPtr ppCCatConfigInfo = IntPtr.Zero;

try
{
pICatParms.GetCCatConfigInfo(out ppCCatConfigInfo);

_tagCCatConfigInfo theStruct = (_tagCCatConfigInfo)Marshal.PtrToStructure(ppCCatConfigInfo, typeof(_tagCCatConfigInfo)); <-- Access violation

}
catch(exception ex)
}
Debug.WriteLine("Exception: {0}", ex.Message);
}
finally
{
if (null != pICatParms) { Marshal.ReleaseComObject(pICatParms); }
if (null != pICatItem) { Marshal.ReleaseComObject(pICatItem); }
if (null != pINotify) { Marshal.ReleaseComObject(pINotify); }
}
}




When I hit "tagCCatConfigInfo theStruct = (_tagCCatConfigInfo)Marshal.PtrToStructure(ppCCatConfigInfo, typeof(_tagCCatConfigInfo))"

The system crashes and the output window reads - A first chance exception of type 'System.AccessViolationException' occurred in mscorlib.dll
The error logs do not have any entries for the exception and the SMTP Service stops.

Any ideas?

Thanks
Al
0 new messages