dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Imported C# DLL in C++ project - left of '.ToString' must have class/struct/union

  1. #1
    Join Date
    Oct 2019
    Posts
    10

    [RESOLVED] Imported C# DLL in C++ project - left of '.ToString' must have class/struct/union

    I have a project needing simultaneous access to 2 different APIs. One API library is only available in C++ and the other in C#. I am building the main project in C++ and importing the C# DLL. Right now I am trying to figure out how to do that step properly. I created some sample code to try to figure this out. Here is a test DLL in C#:

    Code:
    namespace CsharpDLL
    {
        using System;
    
        public class classTime
        {
            public classTime() { }
            public DateTime Latest()
            {
                return DateTime.Now;
            }
        }
    }
    Here is the C++ event handler that tries to access the above imported class. m_edit1_text is a CString text-control variable for an edit box:

    Code:
    void CCppCsharpComboDlg::OnBnClickedDate()
    {
    	// TODO: Add your control notification handler code here
    
    	CsharpDLL::classTime^ myDate = gcnew CsharpDLL::classTime;
    
    	m_edit1_text = myDate->Latest.ToString;
    		// Update the dialog with the values
    	UpdateData(FALSE);
    }
    The m_edit1_text assignment generates this error: left of '.ToString' must have class/struct/union

    I am having trouble spotting what is causing the error.

  2. #2
    Join Date
    Oct 2019
    Posts
    10

    Re: Imported C# DLL in C++ project - left of '.ToString' must have class/struct/union

    I am using Visual C++ & C# 2019 v142 with /clr enabled in both projects. I am using .NET 4.7.2.

  3. #3
    Join Date
    Feb 2017
    Posts
    478

    Re: Imported C# DLL in C++ project - left of '.ToString' must have class/struct/union

    Quote Originally Posted by bigteks View Post
    The m_edit1_text assignment generates this error: left of '.ToString' must have class/struct/union
    From the error message and your code it seems like Latest is a method. In that case () is missing and it should probably look like this,
    Code:
    m_edit1_text = myDate->Latest().ToString;
    Also to me ToString sounds like a method name and in that case another pair of parentheses are probably missing,

    Code:
    m_edit1_text = myDate->Latest().ToString();

  4. #4
    Join Date
    Oct 2019
    Posts
    10

    Re: [RESOLVED] Imported C# DLL in C++ project - left of '.ToString' must have class/s

    Thanks Wolle, that was it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)