1

is there any way to make a wrapper clr:safe for a project in C++ unmanaged?

My little story started this way,
"Boy, you have to do a project 'C# COM Interop' but this one have to use a 'C++ library' and must result in only 'one' (dll COM)."
Ok, after a few days searching, I realized that is possible to use C++ library in two ways: adding in Resources and calling with PInvoke or creating a wrapper C++/CLI. With PInvoke I can not have only one dll(right?). So I opted for the second option "wrapper C++/CLI". Seemed easy at the beginning, I recompile the library Visual Studio 2005 to 2010, create a CLR project (with keypair.snk and re-signed) added the library. Works! \0/ Now I will use the ILMerge, ohhhoo what is this? Only clr:safe? Why? OK, I try to recompile C++/CLI to clr:safe but erros appears...

How can I fix this?

Thanks in advanced,

Cobaia
  • 1,503
  • 3
  • 22
  • 41
  • I'm not sure how any of this is related to COM. There are three kinds of interop: P/Invoke; C++ interop (codename "It Just Works"); COM interop. Since you haven't told us what errors appear, there's no way we can help fix them. – Ben Voigt Jul 21 '11 at 05:53
  • possible duplicate of [How to link C# and C++ assemblies into a single executable?](http://stackoverflow.com/questions/2609056/how-to-link-c-and-c-assemblies-into-a-single-executable) – Ben Voigt Jul 21 '11 at 05:56
  • @Ben Voigt. The erros is like "error C4956: 'const wchar_t *' : this type is not verifiable"... After searching some more, I realized that it is impossible to merge unmanaged to managed code. I'll try this "http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/". if not possible, I'll add resources in the dll and use P/Invoke. Thanks – Cobaia Jul 21 '11 at 11:16

1 Answers1

0

ILMerge isn't the right tool for this.

Instead, you compile the C# to a .netmodule, and pass that to the C++/CLI linker along with all the C++/CLI object files.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • Sorry, I can not understand your answer. I have em COM C#, this use (C# lib thats use C++/CLI clr not safe). I want to deploy in a single dll. thanks – Cobaia Jul 21 '11 at 11:11
  • @Cabaia: Look at http://stackoverflow.com/questions/2609056/how-to-link-c-and-c-assemblies-into-a-single-executable – Ben Voigt Jul 21 '11 at 13:00
  • Thanks. I tried "embed the unmanaged DLL as a resource if you extract it yourself to a temporary directory " http://stackoverflow.com/questions/666799/embedding-unmanaged-dll-into-a-managed-c-dll and works! But I can not use GetManifestResourceStream :( so I used Properties.Resources.UnmanagedDLL. – Cobaia Jul 22 '11 at 14:20