Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I'm using ImoduleConfig Interface in C# like:

C#
[ComImport, SuppressUnmanagedCodeSecurity, Guid("486F726E-4D43-49B9-8A0C-C22A2B0524E8"),
     InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IModuleConfig : IPersistStream
    {

        new void GetClassID([Out] out Guid pClassID);
        [PreserveSig]
        int SetValue([In, MarshalAs(UnmanagedType.LPStruct)] Guid pParamID, [In]ref Object pValue);

        [PreserveSig]
        int GetValue([In, MarshalAs(UnmanagedType.LPStruct)] Guid pParamID, ref Object pValue);

        [PreserveSig]
        int GetParamConfig([In, MarshalAs(UnmanagedType.LPStruct)] Guid pParamID, out IParamConfig pValue);

        [PreserveSig]
        [return: MarshalAs(UnmanagedType.U1)]
        bool IsSupported([In, MarshalAs(UnmanagedType.LPStruct)] Guid pParamID);

        [PreserveSig]
        int SetDefState();

        [PreserveSig]
        int EnumParamsint(ref long pNumParams, ref Guid pParamIDs);

        [PreserveSig]
        int CommitChanges([Out] out Object pReason);

        [PreserveSig]

        int DeclineChanges();

        [PreserveSig]
        void SaveToRegistry(
    [In] Int32 hKeyRoot,
    [In, MarshalAs(UnmanagedType.BStr)] String pszKeyName,
    [In, MarshalAs(UnmanagedType.Bool)] bool bPreferReadable);

        [PreserveSig]

        void LoadFromRegistry(
            [In] Int32 hKeyRoot,
            [In, MarshalAs(UnmanagedType.BStr)] String pszKeyName,
            [In, MarshalAs(UnmanagedType.Bool)] bool bPreferReadable);


        [PreserveSig]


        int RegisterForNotifies([In, MarshalAs(UnmanagedType.Interface)] ref IModuleConfig pModuleCallback);

        [PreserveSig]

        int UnregisterFromNotifies([In, MarshalAs(UnmanagedType.Interface)] ref IModuleConfig pModuleCallback);

    }


When calling the ComitChanges method I'm getting AcessViolation exception.

object obj2 = new object();
hr = pNetworkSourceModuleConfig.CommitChanges(out obj2);



Please Help.

Thanks in Advance
Posted
Comments
Bernhard Hiller 25-May-12 8:30am    
Handling that out Object pReason is more complicated. It is an out parameter, i.e. the function will write the value to that parameter which is then available in the calling function. If it was a call within the .Net framework, actually no instatiation is required. But here, the object gets created in the non-managed world. You have to create some block of memory, safeguard it from GC, and somehow pass it to that function. I do not remember further details...
Bob_Singh 25-May-12 9:30am    
Hi Bernhard
Can you please explain me in more detail.if you can provide code snippet it would be great.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900