Click here to Skip to main content
14,927,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a COM written in C++ accessed by .NET C# application.

The COM was originally written by someone else and has already been launched as a product many years ago.

Now, I've had to make alterations to it.

I added a few interfaces and this seems to work.

I then added a few methods to an interface that existed before I inherited this job. The C# application accessing it thinks that it is made to write into protected memory and fails at runtime.

The C# bit definitely knows that the new methods exist.

It's not some memory allocation problem within the COM as I've debugged from the COM side as well and it doesn't get as far as calling the COM methods.

Have I missed something?

// MyCOM.idl
[ 
 object, 
 uuid(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX),
 oleautomation,
 pointer_default(unique)
] interface IMyInterface: IUnknown
{
	[helpstring("method Method1") HRESULT Method1();
	[helpstring("method MethodNewlyAdded") HRESULT MethodNewlyAdded();
}

[ 
 object, 
 uuid(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX),
 oleautomation,
 pointer_default(unique)
] interface INewInterface: IUnknown
{
	[helpstring("method NewMethod") HRESULT NewMethod();
}

coclass MyCoClass
{
	interface IMyInterface;
	interface INewInterface;
}


// MyApp.cs
public void MyAppMethod()
{
	MyCOM.IMyInterface myCOM = new MyCOM.IMyInterface;
	myCOM.Method1(); // OK
	myCOM.MethodNewlyAdded(); // Unhandled memory exception!


	MyCOM.INewInterface myNewCOM = new MyCOM.INewInterface;
	myNewCOM.NewMethod(); // OK
}
Posted
Updated 23-Jan-13 19:27pm
v2

I think what's your missing is id

Try to enumerate all your methods in the interface and assigns the ids, something like this:

C++
interface IMyInterface: IUnknown
{
	[id(1), helpstring("method Method1") HRESULT Method1();
	[id(2), helpstring("method MethodNewlyAdded") HRESULT MethodNewlyAdded();
}


Also, try to make your interface dual, like this:

C++
[
    object,
    uuid(?????),
    dual,
    helpstring("IMyInterface Interface"),
    pointer_default(unique)
]
   
Comments
PaulowniaK 24-Jan-13 1:12am
   
Sadly, neither modification seems to help... :(
There is a wrapper module further up that implements stubs. I forgot to add the new methods to the list of stubs. :doh:
   

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