1

I am developing a managed lib (using Microsoft Web Services) and I am including it into a c++ project. The project doesn't use /clr option, so when I include my library's header file VS2005 show me an error saying I have to use /clr option. Doing this I have a incompatibility with /EHs command line option (error D8016), but changing from EHs to no exception handling not solving problem and keep showing me same error .

Any suggestion is welcome.

Thank you in advance.

11
  • 7
    You can't write C# and C++ code in the same project. Commented May 23, 2011 at 10:31
  • 3
    You cannot create a managed lib without using the /clr option. Commented May 23, 2011 at 10:35
  • @CodyGray : Yes you can; read up on .netmodule files. Commented May 23, 2011 at 15:01
  • @user765829 : /EHa must be used in conjunction with /clr. Commented May 23, 2011 at 15:02
  • @ildjarn: Where does that link say anything about C#? Commented May 23, 2011 at 15:28

4 Answers 4

4

If you have unmanaged C++ code and want to use managed code, you have a few options:

  • Change your unmanaged code to C++/CLI, by use of the /clr switch.
  • Write a C++/CLI wrapper library. It could DLL-export unmanaged functions which you call in your unmanaged code.
  • Skip the wrapper library and directly DLL-export unmanaged functions via this library.
Sign up to request clarification or add additional context in comments.

Comments

1

You can't use a managed lib from an unmanaged c++ application. Since you add the /clr option, your c++ application becomes managed too (just for the record :) )

Here's what might help you: http://msdn.microsoft.com/en-us/library/ffkc918h.aspx - the restrictions of the /clr option.

2 Comments

Almost correct: To use a managed library from unmanaged code, you need to create a wrapper library or otherwise export unmanaged symbols.
no, its wont work , in that link it tells tat wat are thing clr not compitable , i wann to solve this error , no solution till found on specified link :(
0

It is possible to write managed c++ adapter, that will call the C# library, and call this adapter from unmanaged c++ program as you would usually call a normal c++ library. You will compile your adapter library with /clr and your main c++ program without /clr if for whatever reason you want to keep it unmanaged.

Comments

0

You can embed a mono environment and start an AppDomain. mono's runtime API will allow you to instantiate classes and call members on them. It will be clumsy, but is will work

http://www.mono-project.com/Embedding_Mono

Note that Mono is a full .Net 4.0 compliant CLR and it can work with the Microsoft core libraries on Windows.

On windows and Unix it can work with the Mono corlib/class libraries. There are areas not covered in Mono, but they seem to get sparse. You can use the MoMa tool to spot whether your application uses incompatible/incomplete APIs.

Or you can just use the Microsoft .NET framework, assuming you're on windows anyway!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.