vc++2003 interop call c# DLL
-
Hello, I'm maintaining a previous system with VC++2003, and have to add more functions. I deveoped them with C# DLL. But now I can't call C# DLL from VC++ code. pasted some code piece as below: ------------------------ c# part: using System; namespace MyCSClass { public class CSClass { public CSClass(){} public void Print(){ System.Console.Writeline("Hello, I'm in CSClass"); } } } -------------------- C++ part: #using "..." //the DLL using namespace MyCSClass; void CPlus::CallCSClass() { CSClass ^ obj = gcnew CSClass(); obj->Print(); } ----------------- The error is: error C2143: Syntax error: missing ";" (before "^") error C2065: "obj" undefined. error C2227: "->Print" ..... Above is my translation, orginal is below: error C2143: 语法错误 : 缺少“;”(在“^”的前面) error C2143: 语法错误 : 缺少“;”(在“^”的前面) error C2065: “objAuthen” : 未声明的标识符 error C2227: “->Authenticate”的左侧必须指向类/结构/联合类型是“'unknown-type'” Anyone can help me? Thanks!
Code Project
-
Hello, I'm maintaining a previous system with VC++2003, and have to add more functions. I deveoped them with C# DLL. But now I can't call C# DLL from VC++ code. pasted some code piece as below: ------------------------ c# part: using System; namespace MyCSClass { public class CSClass { public CSClass(){} public void Print(){ System.Console.Writeline("Hello, I'm in CSClass"); } } } -------------------- C++ part: #using "..." //the DLL using namespace MyCSClass; void CPlus::CallCSClass() { CSClass ^ obj = gcnew CSClass(); obj->Print(); } ----------------- The error is: error C2143: Syntax error: missing ";" (before "^") error C2065: "obj" undefined. error C2227: "->Print" ..... Above is my translation, orginal is below: error C2143: 语法错误 : 缺少“;”(在“^”的前面) error C2143: 语法错误 : 缺少“;”(在“^”的前面) error C2065: “objAuthen” : 未声明的标识符 error C2227: “->Authenticate”的左侧必须指向类/结构/联合类型是“'unknown-type'” Anyone can help me? Thanks!
Code Project
Based on the compiler errors, it appears that the C++ file is not getting built with the /clr option. Check the project build properties to make sure CLR support is turned on. Another thing to check is that you've added a reference to the C# assembly. John
-
Based on the compiler errors, it appears that the C++ file is not getting built with the /clr option. Check the project build properties to make sure CLR support is turned on. Another thing to check is that you've added a reference to the C# assembly. John
Yes, I'm sure turned on /clr. the building command line: /O2 /AI "C:\git-hub\im-server\emc2s\MyTestInterop\Release" /AI "Release" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /EHsc /MD /GS /Yu"stdafx.h" /Fp"Release/MyTestInterop.pch" /Fo"Release/" /Fd"Release/vc70.pdb" /W3 /nologo /c /Wp64 /Zi /clr /TP /FU "C:\git-hub\im-server\emc2s\EMLdap\obj\Release\EMLdap.dll" /FU "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorlib.dll" Another, I'm sure added C# assembly in reference. Anyother ideas to resolve it?
Code Project
-
Yes, I'm sure turned on /clr. the building command line: /O2 /AI "C:\git-hub\im-server\emc2s\MyTestInterop\Release" /AI "Release" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /EHsc /MD /GS /Yu"stdafx.h" /Fp"Release/MyTestInterop.pch" /Fo"Release/" /Fd"Release/vc70.pdb" /W3 /nologo /c /Wp64 /Zi /clr /TP /FU "C:\git-hub\im-server\emc2s\EMLdap\obj\Release\EMLdap.dll" /FU "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorlib.dll" Another, I'm sure added C# assembly in reference. Anyother ideas to resolve it?
Code Project
Perhaps open your assembly with ILDasm or DotPeek and make sure the class is exported properly. Can you access it from another C# solution?
-
Perhaps open your assembly with ILDasm or DotPeek and make sure the class is exported properly. Can you access it from another C# solution?