rreischl
asked on
using strcopy: cannot convert parameter 2 from 'const System::String __gc *' to 'const char *'
Hello,
I am just learning OOP and C++.net. I need to modify this code to make it
work. Any help would be greatly appreciated!!!!!
////////////////////////// ////////// ////////// ////////// ////////// ////
// sends text to the controller, wait for response, return response
String * ODevice::SendAndGet( const String * Cmd ) const
{
String * Response = "";
if( hOms != NULL ) { // if connected
char resp[OMS_MAX_RESPONSE] = {'\0'}, cmd[OMS_MAX_RESPONSE] = {'\0'};
strcpy( cmd, Cmd ); // dll takes only standard C types
SendAndGetString( hOms, cmd, resp );
Response->Format( "%s", resp );
}
return( Response );
}
Here are the errors I receive:
test.cpp(74) : error C2664: 'strcpy' : cannot convert parameter 2 from 'const System::String __gc *' to 'const char *' Cannot convert a managed type to an unmanaged type
test.cpp(76) : error C2664: 'System::String __gc *System::String::Format(Sy stem::Stri ng __gc *,System::Object __gc *)' : cannot convert parameter 2 from 'char [125]' to 'System::Object __gc *' Cannot convert an unmanaged type to a managed type
This is at the top:
#using <mscorlib.dll>
using namespace System;
Here is the class definition for ODevice:
class ODevice
{
public:
BYTE GetDone( void ) const; // calls DLL function to get done flags
void ClrDone( const BYTE ); // calls DLL function get clear done flags
String * GetDrvrVrsn( void ) const; // calls DLL function to get driver version
String * SendAndGet( const String * ) const; // sends text to the controller and returns controller's response
void Disconnect( void ); // disconnect from the controller
void Connect( const String * ); // connect to the controller
String * GetName( void ) const; // returns the name of the current device
ODevice(); // standard constructor
~ODevice(); // standard destructor
private:
HANDLE hOms; // handle to the controller
};
Hopefully this is enough information.
Thanks in advance!
I am just learning OOP and C++.net. I need to modify this code to make it
work. Any help would be greatly appreciated!!!!!
//////////////////////////
// sends text to the controller, wait for response, return response
String * ODevice::SendAndGet( const String * Cmd ) const
{
String * Response = "";
if( hOms != NULL ) { // if connected
char resp[OMS_MAX_RESPONSE] = {'\0'}, cmd[OMS_MAX_RESPONSE] = {'\0'};
strcpy( cmd, Cmd ); // dll takes only standard C types
SendAndGetString( hOms, cmd, resp );
Response->Format( "%s", resp );
}
return( Response );
}
Here are the errors I receive:
test.cpp(74) : error C2664: 'strcpy' : cannot convert parameter 2 from 'const System::String __gc *' to 'const char *' Cannot convert a managed type to an unmanaged type
test.cpp(76) : error C2664: 'System::String __gc *System::String::Format(Sy
This is at the top:
#using <mscorlib.dll>
using namespace System;
Here is the class definition for ODevice:
class ODevice
{
public:
BYTE GetDone( void ) const; // calls DLL function to get done flags
void ClrDone( const BYTE ); // calls DLL function get clear done flags
String * GetDrvrVrsn( void ) const; // calls DLL function to get driver version
String * SendAndGet( const String * ) const; // sends text to the controller and returns controller's response
void Disconnect( void ); // disconnect from the controller
void Connect( const String * ); // connect to the controller
String * GetName( void ) const; // returns the name of the current device
ODevice(); // standard constructor
~ODevice(); // standard destructor
private:
HANDLE hOms; // handle to the controller
};
Hopefully this is enough information.
Thanks in advance!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered: Points to Salte
Please leave any comments here within the next seven days. Experts: Silence
means you don't care.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
-bcl (bcladd)
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Answered: Points to Salte
Please leave any comments here within the next seven days. Experts: Silence
means you don't care.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
-bcl (bcladd)
EE Cleanup Volunteer
Instead of strcpy(), just do:
cmd = Cmd;
These are classes and C++ will copy/convert the entire class object (struct) where C would not.
The same for the returned value:
Result = resp;
Kdo