C# Interface methods gets wrong prototype when using COM interop

  • Thread starter Thread starter kli
  • Start date Start date
K

kli

I have a very peculiar problem. I have a c# class library that a access
from a C++ MFC client through COM introp. This work almost well. One
special interface method is translated wrong when exporting to a .tlb
file and importing it into the client app.

The C# interface method snippet:
namespace Scandpower.pt.GridGenerator.Geometry
{
public interface IPipe
{
double Angle(Constants.ANGLETYPE type);
}
}

is when viewing the .tlb file changed to:

IPipe::angle(ByVal type As ANGLETYPE) As Double

As you see the method has the small caps intead of big. This shouldn't
be a big problem, but when my collegue is compiling the same code on
his machine the .tlb file is correct!!

I've used the .dll created a from his machine and used tlbexp on it.
Then the .tlb is correct for me as well. So it seems like a C# compiler
issue. Any localization stuff or other "hidden" settings that can
produce this kind of error?

best,
Kjetil.
 
I've got the same problem with methods called Id() ..... they get converted
to id() ....

A bit of a pain!!!

Tom Kearney
 
I've got the same problem with methods called Id() ..... they get converted
to id() ....

A common reason for this problem is explained in this KB article

BUG: MIDL Changes the Case of Identifier in Generated Type Library
http://support.microsoft.com/kb/q220137/

Note that the bug is in OleAut. MIDL is just a frontend, and so is
TlbExp.

I don't know if this explains Kjetil's issue though, since this should
be consistent across machines if compiling the same typelib.


Mattias
 
Thanks Mattias!
You put me on the right track.
Even though my problem isn't related to the MIDL compiler, but C#
compiler, the cause of the problem seems to be the same. I have another
method in another namespace and interface:
int IGeoGenerator::AddAngleClass(double angle);
when I changed it to:
int IGeoGenerator::AddAngleClass(double i_dAngle);
I got the correct signature on my
IPipe::Angle method.

Although I was somewhat abashed by the status comment in the article!!:
Quote:
STATUS
This behavior is by design.

best,
Kjetil.

Mattias Sjögren skrev:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top