none of the 21 overloads could convert all the argument types

Hello I'm getting these errors in building my simple app in VS2017
1
2
3
 error C2665: 'System::Windows::Forms::MessageBox::Show': none of the 21 overloads could convert all the argument types
note: could be 'System::Windows::Forms::DialogResult System::Windows::Forms::MessageBox::Show(System::String ^)
note: while trying to match the argument list '(std::string)

Code ostuff.h
1
2
3
4
5
6
7
8
9
#include <stdio.h>
#include <string> 
#pragma once
#pragma comment(lib, "user32.lib")
class ostuff
{
	public:
		std::string info();
};

ostuff.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "ostuff.h"
#include <windows.h>
#include <stdio.h>
#include <string> 
#pragma comment(lib, "user32.lib")
std::string ostuff::info()
{
	std::string msg;

	SYSTEM_INFO siSysInfo;

	// Copy the hardware information to the SYSTEM_INFO structure. 

	GetSystemInfo(&siSysInfo);

	// Display the contents of the SYSTEM_INFO structure. 

	msg = "Hardware information: \n";
	msg += "  OEM ID: %u\n", siSysInfo.dwOemId;
	msg += "  Number of processors: %u\n", siSysInfo.dwNumberOfProcessors;
	msg += "  Page size: %u\n", siSysInfo.dwPageSize;
	msg += "  Processor type: %u\n", siSysInfo.dwProcessorType;
	msg += "  Minimum application address: %lx\n", siSysInfo.lpMinimumApplicationAddress;
	msg += "  Maximum application address: %lx\n", siSysInfo.lpMaximumApplicationAddress;
	msg += "  Active processor mask: %u\n", siSysInfo.dwActiveProcessorMask;
	return msg;
}

and on button click myform.h file
very top:
#include "ostuff.h"
1
2
3
4
5
6
private: System::Void cpu_button_Click(System::Object^  sender, System::EventArgs^  e)
		{
			ostuff b;
			std::string msg = b.info();
			MessageBox::Show(msg);///error is here
		}

What I doing wrong?
closed account (E0p9LyTq)
What I doing wrong?

Lines 19-25 you are expecting the compiler to concatenate a formatted string to another string, without actually creating that formatted string.

C++ has no C++ standard library methods that I know of to create a formatted string, you need to use a C library function for that. Either sprintf or sprintnf.

http://www.cplusplus.com/reference/cstdio/sprintf/
http://www.cplusplus.com/reference/cstdio/snprintf/
According to sprintf example I have to convert msg variable to char?
There are also
http://www.cplusplus.com/reference/string/to_string/
and
http://www.cplusplus.com/reference/sstream/ostringstream/ostringstream/


That, however, is not the shown error.

That error is in calling Show() with a std::string.
Alas, the Show() does not know std::string. It expects some System::String.

You have to convert the std::string into System::String, or to not create a std::string in the first place.
Thanks, changed from std to system and everything now works, but now trying to use this function: http://www.cplusplus.com/forum/general/146576/#msg771172 to get cpu temps, but it throws these errors:
1
2
3
4
5
6
1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\um\wbemcli.h(1268): error C2872: 'byte': ambiguous symbol
1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\shared\rpcndr.h(191): note: could be 'unsigned char byte'
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\cstddef(22): note: or       'std::byte'
1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\um\wbemcli.h(1274): error C2872: 'byte': ambiguous symbol
1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\shared\rpcndr.h(191): note: could be 'unsigned char byte'
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\cstddef(22): note: or       'std::byte'

Also tried this code, but throws foreach and managementobject is undenfined
1
2
3
4
5
6
7
8
9
ManagementClass processClass = new ManagementClass(@"root\WMI:MSAcpi_ThermalZoneTemperature");

foreach (ManagementObject service in processClass.GetInstances())

{

MessageBox.Show("CPU Temperature: " + service.GetPropertyValue("CurrentTemperature"));

}
Last edited on
Do you, by any chance, have using namespace std; in your sources?
Do you use using namespace std somewhere in your code?
byte is a type in .NET but also std::byte is a new C++ type so it's not clear for the compiler which one you want to use.

One way to do this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
SYSTEM_INFO siSysInfo = {0};
GetSystemInfo(&siSysInfo);

std::ostringstream oss;
oss << "Hardware information: \n";
oss << "OEM ID: " << siSysInfo.dwOemId << "\n"; 
oss << "  Number of processors: " << siSysInfo.dwNumberOfProcessors << "\n";
oss << "  Page size: " << siSysInfo.dwPageSize << "\n";
oss << "  Processor type: " << siSysInfo.dwProcessorType << "\n";
oss << "  Minimum application address: " << siSysInfo.lpMinimumApplicationAddress << "\n";
oss << "  Maximum application address: " << siSysInfo.lpMaximumApplicationAddress << "\n";
oss << "  Active processor mask: " <<  siSysInfo.dwActiveProcessorMask  << "\n";
String^ msg = gcnew String(oss.str().c_str());
MessageBox::Show(msg);


Output:
https://pasteboard.co/HcLNfwy.jpg
Found and deleted thanks, but it shows -273.25 how to display normal temp?
temp output:
1
2
3
4
LONG temp;
	GetCpuTemperature(&temp);
	double tmp = (temp / 10 - 273.15);
	msg += "temp: "+ tmp+"\n";
Last edited on
Topic archived. No new replies allowed.