-
November 7th, 2019, 12:06 AM
#1
[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.
-
November 7th, 2019, 12:22 AM
#2
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.
-
November 7th, 2019, 12:45 AM
#3
Re: Imported C# DLL in C++ project - left of '.ToString' must have class/struct/union
Originally Posted by bigteks
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();
-
November 7th, 2019, 12:50 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|