Catch in unmamaged code won't link

  • Thread starter Thread starter Bret Pehrson
  • Start date Start date
B

Bret Pehrson

Try this one on for size:

// Managed C++ Project/code
#pragma unmanaged
struct S
{
};

void Func()
{
try
{
}
catch (S * s)
{
}
}
#pragma managed


When compiled, produces the following:

LINK : error LNK2020: unresolved token (0A000013) ??_7type_info@@6B@


Poking around in the generated .obj file w/ ildasm for token 0A000013 reveals
the following:

// MemberRef #9
// -------------------------------------------------------
// Member: (0a000013) __CxxUnregisterExceptionObject:
// CallCnvntn: [DEFAULT]
// ReturnType: CMOD_OPT System.Runtime.CompilerServices.CallConvCdecl Void
// 2 Arguments
// Argument #1: Ptr Void
// Argument #2: I4
// CustomAttribute #1 (0c000013)
// -------------------------------------------------------
// CustomAttribute Type: 0a00000c
// CustomAttributeName: Microsoft.VisualC.DecoratedNameAttribute :: instance
void .ctor(class System.String)
// Length: 51
// Value : 01 00 2e 3f 5f 5f 43 78 78 55 6e 72 65 67 69 73 >
..?__CxxUnregis<
// : 74 65 72 45 78 63 65 70 74 69 6f 6e 4f 62
6a 65 >terExceptionObje<
// : 63 74 40 40 24 24 4a 30 59 41 58 50 41 58
48 40 >ct@@$$J0YAXPAXH@<
// : 5a 00
00 >Z <
// ctor args: ("?__CxxUnregisterExceptionObject@@$$J0YAXPAXH@Z")
//


Obviously, __CxxUnregisterExceptionObject isn't something that I've defined,
but is a core component that appears to be missing. Yes, C++ exceptions are
enabled for the project...


Anyone seen this, and how they resolved it?
 
Ok, this is purely bogus.

I ended up scrapping that project, creating a new one, pasting in the *exact
same code*, and it now builds fine.

I probably spent an hour pouring over the project configuration settings,
comparing the old w/ the new, and found virtually no differences.

Come on MS -- stop wasting my time w/ your crappy product that I paid for.

Bret said:
Try this one on for size:

// Managed C++ Project/code
#pragma unmanaged
struct S
{
};

void Func()
{
try
{
}
catch (S * s)
{
}
}
#pragma managed

When compiled, produces the following:

LINK : error LNK2020: unresolved token (0A000013) ??_7type_info@@6B@

Poking around in the generated .obj file w/ ildasm for token 0A000013 reveals
the following:

// MemberRef #9
// -------------------------------------------------------
// Member: (0a000013) __CxxUnregisterExceptionObject:
// CallCnvntn: [DEFAULT]
// ReturnType: CMOD_OPT System.Runtime.CompilerServices.CallConvCdecl Void
// 2 Arguments
// Argument #1: Ptr Void
// Argument #2: I4
// CustomAttribute #1 (0c000013)
// -------------------------------------------------------
// CustomAttribute Type: 0a00000c
// CustomAttributeName: Microsoft.VisualC.DecoratedNameAttribute :: instance
void .ctor(class System.String)
// Length: 51
// Value : 01 00 2e 3f 5f 5f 43 78 78 55 6e 72 65 67 69 73 >
.?__CxxUnregis<
// : 74 65 72 45 78 63 65 70 74 69 6f 6e 4f 62
6a 65 >terExceptionObje<
// : 63 74 40 40 24 24 4a 30 59 41 58 50 41 58
48 40 >ct@@$$J0YAXPAXH@<
// : 5a 00
00 >Z <
// ctor args: ("?__CxxUnregisterExceptionObject@@$$J0YAXPAXH@Z")
//

Obviously, __CxxUnregisterExceptionObject isn't something that I've defined,
but is a core component that appears to be missing. Yes, C++ exceptions are
enabled for the project...

Anyone seen this, and how they resolved it?
 
Hi Bret,

I posted reply in your former post on this issue. As you mentioned, I can't
reproduce the problem on my side. The same code can be built without any
error on both VS.NET 2002 and VS.NET 2003.

Have you installed any VS.NET add-in? I think you can use the tool WinDiff
in C:\Program Files\Microsoft Visual Studio .NET\Common7\Tools\Bin (for
vs.net 2002, if vs.net 2003, then change to Microsoft Visual Studio .NET
2003\...) to tell the difference in two project to see if you can find
anything special there.

Thanks.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Bret,

Thanks for your update.

From the repro sample, I think we get the root cause of why you met this
problem. The reason is that the project type is not correct. It is not
related to the project name.

For the code we are using, we need to create .NET console application
instead of a class library or a DLL project. You could test the same code
in a Visual C++.NET .NET console application. It should be working fine.

If there is anything unclear, please feel free to let me know.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top