Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C# COM
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 23-Jan-13 19:25pm
Edited 23-Jan-13 20:27pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I think what's your missing is id
 
Try to enumerate all your methods in the interface and assigns the ids, something like this:
 
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:
 
	[
		object,
		uuid(?????),
		dual,
		helpstring("IMyInterface Interface"),
		pointer_default(unique)
	]
  Permalink  
Comments
PaulowniaK at 24-Jan-13 1:12am
   
Sadly, neither modification seems to help... :(
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

There is a wrapper module further up that implements stubs. I forgot to add the new methods to the list of stubs. D'Oh! | :doh:
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 BillWoodruff 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100