2

I am building a c# application, in my application, I load a c++/cli dll, and calling its function.

I have declare a value class in my c++/cli class.

public value class S_OpenParam {
        public :
          int iPort;
          char* szIpAddress;
          int iBaudRate;
};

Then , I am trying to initialize my S_OpenParam in my c# application.

I am facing problem on initialize the char* szIpAddress

myObj.S_OpenParam sParam;
sParam.iBaudRate = 0;
sParam.iPort = 0;

When I try to assign a value to it:

sParam.szIpAddress = "127.0.0.1";

It shows the type is sbyte*

enter image description here

Do you know how to initialize it ?

2
  • whats the acutal type of szIpAddress in c#? I mean, what is it expecting?
    – nozzleman
    Dec 30, 2016 at 9:09
  • Just don't do that! C# is a thoroughly modern language, it gives you no easy rope to hang yourself with these ancient 8-bit encodings. Anything declared public must use String^ instead of char*. It is up to your C++/CLI code, if necessary, to convert that System::String to a legacy encoding. Not making that necessary is easy too, encoding an IP address in an 8-bit string is something you had to do 25 years ago. We're in the 21st century today. Dec 31, 2016 at 10:10

1 Answer 1

1

Since you are in a C++/CLI dll, why don't you use String^ instead of char*, so that you will be able to update it from c# without problems ?

public value class S_OpenParam {
        public :
          int iPort;
          String^ szIpAddress; <-- String^ instead of char*
          int iBaudRate;
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.