Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I create an interface in idl file and genreated tlb in COM
C++
[
        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* );
                             }
<pre>

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.

<pre lang="vb">
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.

VB
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.”

What I have tried:

I know this is a long question. Thanks for going through this, any help is greatly appreciated. Sorry for any typos
Posted
Updated 3-Jun-18 22:06pm
v4

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