none
Attempted to read or write protected memory. This is often an indication that other memory is corrupt while calling a .NET Object from COM RRS feed

  • Question

  • I create an interface in idl file and genreated tlb in COM

    [
            uuid(E4ACB118-4729-4876-9F84-292815AE173B),
            oleautomation,
            object,
            dual
        ]
    
        interface IUser : IDispatch {
    
                                    [id(0x60030009), helpstring("Brings up Framework Register dialog.")]
    
                                    HRESULT Register([in] BSTR* sUserID,[in] BSTR* sUserName,[in]SalaryDetails* oSalaryDetails,[out, retval] long* );
                                 }
    

    Now using this tlb as reference to my test tool which is in COM I am calling a method after creating the object by CreateObject with Progid as below.

    Dim g_oUserSalDetails as ISalaryDetails
    Set  g_oUserSalDetails = CreateObject(Salary.Application)
    g_oUserSalDetails.Add(“100”,”10,000”)
    Dim g_oUserDetails As IUser
    Set g_oUserDetails = CreateObject(User.Application)
    Dim llngRetun as long
    llngRetun = oUserDetails.Register(“100”,”Demo User”, g_oUserSalDetails)
    

    After the call user details is successfully registered.

    All the above components in COM. Now there is a DOT net application which is doing the similar register. So I have to use the application without changing much code in test tool. So the dot net interface which is same as IUser I have marked its GUID same as IUser as shown below.

    <ComVisible(True), InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("E4ACB118-4729-4876-9F84-292815AE173B")>
    
        Public Interface IEmployee
    
                         Function Register(ByVal EmpID As string,ByVal EmpName as 
                         String, ByVal EmpSalaryDetails as IEmpSalaryDetails) As Integer
        End Interface
    

    On the class that is implementing this interface I have marked the progid as ”User.Application”

    <System.Runtime.InteropServices.ProgId("User.Application"), ComVisible(True)>
        Public Class Employee
            Implements IEmployee
    Function Register(ByVal EmpID As string,ByVal EmpName as String,Byval EmpSalaryDetails as IEmpSalaryDetails) As Integer
    
       **Register implementation**
        End Interface
    
         End Class
    

    I have done the same steps for ISalaryDetails too and ran the regasm to get these values to registry.

    Now In the above com code.

    Dim g_oUserSalDetails as ISalaryDetails
    Set  g_oUserSalDetails = CreateObject(Salary.Application)
    g_oUserSalDetails.Add(“100”,”10,000”)
    Dim g_oUserDetails As IUser
    Set g_oUserDetails = CreateObject(User.Application)
    Dim llngRetun as long
    llngRetun = oUserDetails.Register(“100”,”Demo User”, g_oUserSalDetails)
    

    The create object is creating the object of Employee. I could see in debug window visual basic editor 6.0. But the register method is failing with the error.

    “Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”

    I know this is a long question. Thanks for going through this, any help is greatly appreciated. Sorry for any typos

    Monday, June 4, 2018 4:53 AM

All replies

  • Hi Screendhar Gunda,

    Thank you for posting here.

    Since your question is more related to VB6, you could post a new thread in VB6 forum for suitable support.

    http://www.vbforums.com/forumdisplay.php?1-Visual-Basic-6-and-Earlier

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 5, 2018 2:33 AM
  • My VB is a little rusty, but it looks like your .NET interface explicitly provides the HRESULT as an int return value. By default, a return value on a COM interface is translated into a final out argument and the HRESULT is used to generate an exception for non-success values. You can either change the return value to void or apply PreserveSigAttribute to the method on the interface.
    Wednesday, June 6, 2018 9:53 PM