Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. vc++2003 interop call c# DLL

vc++2003 interop call c# DLL

Scheduled Pinned Locked Moved Managed C++/CLI
helpcsharpc++comquestion
5 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    X Q Wang
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • X X Q Wang

      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

      J Offline
      J Offline
      John Schroedl
      wrote on last edited by
      #2

      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

      X 1 Reply Last reply
      0
      • J John Schroedl

        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

        X Offline
        X Offline
        X Q Wang
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • X X Q Wang

          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

          J Offline
          J Offline
          John Schroedl
          wrote on last edited by
          #4

          Perhaps open your assembly with ILDasm or DotPeek and make sure the class is exported properly. Can you access it from another C# solution?

          X 1 Reply Last reply
          0
          • J John Schroedl

            Perhaps open your assembly with ILDasm or DotPeek and make sure the class is exported properly. Can you access it from another C# solution?

            X Offline
            X Offline
            X Q Wang
            wrote on last edited by
            #5

            Yes, I tried in DotPeek, it works well. Also it can be called in other C# project. Any other ideas?:mad:

            Code Project

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups