Hi,
I am trying to write a replacement for a VB6 dll that is referenced by another VB6 in c# .net.
For now we can only work on the later and I am having some success with this. Except I have run into a problem.
My Enums are being mangling resulting it being called 'A1BACSTrans_BACSAU' instead of the expect 'BACSAU'
the legacy code will (obviously) no longer compile.
Can this be prevented? if so, how? I have heard of modifying the IDL but I can see no references in their to a mangled name only unmangled...
Thank you in advance!
Loading
VulpesPosted Mar 9, 2011, 2:28 PM
Pleased to hear you've finally sorted it out :)
I'm not really surprised the attribute made no difference. The description only seems to make sense in the context of 'mixed mode' C++/CLI where you can have managed and native enums present in the same application and where, in the former case, the enum constants always need to be qualified by the enum name but, in the latter case, they do not.
Jon HPosted Mar 9, 2011, 12:30 PM
Jon HPosted Mar 9, 2011, 12:22 PM
Thank you so much for your help. I found that the 'error MIDL2088 : [uuid] format is incorrect' is actually a bug in MIDL so I installed VS2010 (was meaning to anyway) and even tho the version of MIDL reports as the same I no longer get the error.
I was therefore about to change the enum names back to the way they should be named and hey presto.
But your comment was very helpful as without your additional use of the enum name you DO NOT GET 'intellisense' style listing of the supporting elements.
So to reiterate I
o) created the dll in vs8 using .net 3.5
o) Then I opened the tlb created with the dll (not sure if this is because I selected the com option or not) in OLE-COM Viewer->View Type lib then File->save as IDL.
o) Open IDL in your editor. Change
enum {
BCDStatus_BankErr = 0,
BCDStatus_BankOK = 1,
BCDStatus_BankRedirect = 2,
BCDStatus_NoBank = 3
} BCDStatus;
to
enum BCDStatus;
{
BankErr = 0,
BankOK = 1,
BankRedirect = 2,
NoBank = 3
} BCDStatus;
(not enum values are auto-generated)
I have change the names and added the extra BCDStatus for the intellisense.
o) in a visual studio command line window. midl x.idl
Hey presto!
VulpesPosted Mar 9, 2011, 11:42 AM
enum BCStrategy
{
BCStrategy_BCStratAV = 0,
BCStrategy_BCStratFull = 1,
BCStrategy_BCStratInfo = 2,
BCStrategy_BCStratNone = 3
}
BCStrategy;
In fact, I found an old thread here (http://forums.devx.com/archive/index.php/t-75260.html) suggesting something similar.
If there were a solution at code level, then it would probably take the form of placing an attribute on the enum. The only one I can find which has anything to do with enums is the System.Runtime.CompilerServices.ScopelessEnumAttribute (see http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.scopelessenumattribute.aspx). It's far from clear what that does (the blurb suggests it may be C++ only) though you could try it and see if it helps.
Jon HPosted Mar 9, 2011, 7:39 AM
I think that was 'il' not 'idl' and hence did not carry what I was expecting.
I have since sound this from using OLE/COM Object Viewer.
enum {
BCStrategy_BCStratAV = 0,
BCStrategy_BCStratFull = 1,
BCStrategy_BCStratInfo = 2,
BCStrategy_BCStratNone = 3
} BCStrategy;
However when I save and try and use Midl to create a tbl i get loads of errors
: error MIDL2088 : [uuid] format is incorrect
is there really no way to say at the code level not to mangle these names?!
Jon HPosted Mar 9, 2011, 6:19 AM
public enum BCStrategy
{
BCStratAV = 0,
BCStratFull = 1,
BCStratInfo = 2,
BCStratNone = 3,
}
the name are still mangled to include the enum name.
Jon HPosted Mar 9, 2011, 3:45 AM
.class public auto ansi sealed TestA1Replacement.BCStrategy
extends [mscorlib]System.Enum
{
.custom instance void [mscorlib]System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = ( 01 00 01 00 00 )
.field public specialname rtspecialname int32 value__
.field public static literal valuetype TestA1Replacement.BCStrategy BCStratAV = int32(0x00000000)
.field public static literal valuetype TestA1Replacement.BCStrategy BCStratFull = int32(0x00000001)
.field public static literal valuetype TestA1Replacement.BCStrategy BCStratInfo = int32(0x00000002)
.field public static literal valuetype TestA1Replacement.BCStrategy BCStratNone = int32(0x00000003)
} // end of class TestA1Replacement.BCStrategy
I will try your suggestion in the code though.
Thank you!
VulpesPosted Mar 8, 2011, 5:48 PM
VulpesPosted Mar 8, 2011, 1:55 PM