How can I convert a string from the unmanaged code, and return it as a .NET String, usign the /oldsyntax for CLR?
ReplyI keep having problems with the compilation... that's the error code that Visual Studio Prof 2008 gives me: 1>------ Build started: Project: Managed, Configuration: Debug Win32 ------ 1>Linking... 1>Feedback.obj : error LNK2028: unresolved token (0A000005) "extern "C" void __clrcall ___CxxCallUnwindDtor(void (__clrcall*)(void *),void *)" (?___CxxCallUnwindDtor@@$$J0YMXP6MXPAX@Z0@Z) referenced in function "public: __clrcall Feedback::Feedback(class ManagedLib::Managed ^)" (??0Feedback@@$$FQAM@P$AAVManaged@ManagedLib@@@Z) 1>Stdafx.obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ) 1>Feedback.obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ) 1>Feedback.obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ) 1>Managed.obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ) 1>Managed.obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ) 1>Feedback.obj : error LNK2019: unresolved external symbol "extern "C" void __clrcall ___CxxCallUnwindDtor(void (__clrcall*)(void *),void *)" (?___CxxCallUnwindDtor@@$$J0YMXP6MXPAX@Z0@Z) referenced in function "public: __clrcall Feedback::Feedback(class ManagedLib::Managed ^)" (??0Feedback@@$$FQAM@P$AAVManaged@ManagedLib@@@Z) 1>..\bin\Debug\Managed.dll : fatal error LNK1120: 3 unresolved externals 1>Build log was saved at "file://c:\Documents and Settings\username\Desktop\C# trials\ConsumingUnmanagedCode\Managed\Debug\BuildLog.htm" 1>Managed - 8 error(s), 0 warning(s) 2>------ Build started: Project: Consumer, Configuration: Debug Any CPU ------ 2>c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets : warning MSB3245: Could not resolve this reference. Could not locate the assembly "Managed". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. 2>c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702 /nostdlib- /errorreport:prompt /warn:4 /baseaddress:285212672 /define:DEBUG;TRACE /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /debug+ /debug:full /filealign:4096 /optimize- /out:obj\Debug\Consumer.exe /target:exe /warnaserror- /win32icon:App.ico AssemblyInfo.cs Consumer.cs C:\Documents and Settings\pietrobda\Desktop\C# trials\ConsumingUnmanagedCode\Consumer\Consumer.cs(3,7): error CS0246: The type or namespace name 'ManagedLib' could not be found (are you missing a using directive or an assembly reference?) Compile complete -- 1 errors, 0 warnings 2>Done building project "Consumer.csproj" -- FAILED. ========== Build: 0 succeeded, 2 failed, 1 up-to-date, 0 skipped ==========Reply
Very good and clear article. I was looking for something like this. However, I can not compile the source code. Maybe there was a problem at the time of conversion to VS2008 solution: ///////////////////////////////////////////////// Error 4 error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ) Stdafx.obj Error 5 error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ) Feedback.obj Error 6 error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ) Feedback.obj Error 7 error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ) Managed.obj Error 8 error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ) Managed.obj Error 9 error LNK2019: unresolved external symbol "extern "C" void __clrcall ___CxxCallUnwindDtor(void (__clrcall*)(void *),void *)" (?___CxxCallUnwindDtor@@$$J0YMXP6MXPAX@Z0@Z) referenced in function "public: __clrcall Feedback::Feedback(class ManagedLib::Managed ^)" (??0Feedback@@$$FQAM@P$AAVManaged@ManagedLib@@@Z) Feedback.obj Error 3 error LNK2028: unresolved token (0A000005) "extern "C" void __clrcall ___CxxCallUnwindDtor(void (__clrcall*)(void *),void *)" (?___CxxCallUnwindDtor@@$$J0YMXP6MXPAX@Z0@Z) referenced in function "public: __clrcall Feedback::Feedback(class ManagedLib::Managed ^)" (??0Feedback@@$$FQAM@P$AAVManaged@ManagedLib@@@Z) Feedback.obj Error 10 fatal error LNK1120: 3 unresolved externals ..\bin\Debug\Managed.dll
I'm getting the same error - any luck getting it to work?
ReplyI think that the black diamond of the composition relationships is positioned at the wrong side. It should be on the side of the class that contains the other class.
Hmm.. Do you think the black diamond was the cause of the compilation issues.
ReplyI couldn't debug the Unmanage library, the debugger doesn't recognize the class Each time I set a breakpoint, the break point is turned to a question mark. How can I debug this class, I'm using Visuall 2003.
ReplyThanks to the comments by Sandeep Datta I can now build and run this project under VS2005. I'd like to move away from the old CLR syntax, but get numerous compiler errors if I do. Has anyone updates the project to do this already ? Thanks, Henry
Hi, Any luck with porting this code to the new syntax? Having serious problems! Any help appricated! :) Martin
ReplyThis article is very good and useful. I downloaded the code and it works very well. But my situation is a little bit different. I have a C++ API DLL compiled with VC6, including some C++ class. I want to use these C++ classes in C#. How to include this DLL in my C#.net project? How to wrap these C++ classes into my managed C++ code (DLL project)? I noticed that in your sample, the unmanaged C++ classes are written, compiled on .Net platform. And you include the unmanaged.h into the managed.h file. I already have unmanaged C++ DLL, and I have header file for the unmanaged C++ class. But when I include these unmanaged C++ header file into a managed C++ project (managed.h), it doesn't work. Many compiling errors relating to the unmanaged.h happened. The managed C++ DLL project (wrapper class) can't be compiled. How to deal with this problem? do I need rewrite the unmanaged C++ class header file? is is because the unmanaged C++ class header are writen in VC6 format? will it work if I rewrite the unmanaged C++ header file? And I don't have the source code for unmanaged C++ class (C++ file). Thanks.
I am in the same situation you are. Did you resolve this?
ReplyI get some very cryptic linker errors in the Managed project. Has anyone tried this code in VS 2005?
ReplyI found the article very precise and useful (If I only had found it earlier it would have saved me from several nervous breakdowns...) Can you make some comments about the workarounds to the mixed DLL problem proposed by Microsoft? Link: "http://support.microsoft.com/?id=814472" You already mentioned some parts of it: - Add /noentry to the Additional Options field of the Command Line page. - Add msvcrt.lib to the Additional Dependencies field of the Input page. - Remove nochkclr.obj from the Additional Dependencies field of the Input page. - Add __DllMainCRTStartup@12 to the Force Symbol Reference field of the Input page. I find the next part of the solution somewhat confusing. I believe this matter is of great interest for the .NET developing community. It would be great if you can give your expert point of view in this matter. Thank You in advance... Federico (Argentina)
ReplyI think this is a very nice approach. Now, my question is what if you are using a MFC-dll (like I do) for the unmanaged part? I link dynamically to MFC so I have a DllMain implicitly and merging this code into the MFC will yield two of them. Maybe it is possible to rename the DllMain entry in the Unmanaged.cpp and provide the calls to the unmanaged dll with something like "EntryPoint=notDllMain". The only thing is, I don't know where to put that. Would this be a reasonable approach? Thanks.
Reply