C ++代码转换为C# [英] C++ Code to C#

查看:98
本文介绍了C ++代码转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对开发非常陌生,一直在努力学习C#.我有一个用C ++编写的应用程序,超出了我的深度,我想知道是否有人可以解释如何在c#中重新创建它.
该应用程序通过套接字连接将消息发送到linux服务.该消息采用结构形式:


I am very new to development and have been sinking my teeth into C#. I have an application that was written in C++ which is out of my depth, and I was wondering if someone could explain how I would recreate this in c#.
The application sends message to linux service via a socket connection. The message is in the form of a struct:


struct alert
{
    unsigned short size;
    unsigned short signature;
    unsigned short bperiod;
    unsigned short bduty;
    unsigned short svolume;
    unsigned short stone;
    unsigned short sfrequency;
    unsigned short speriod;
    unsigned short sduty;
};




该应用程序设计为使用表单,但这没有用,因此我确实通过命令行修改了此设置以接收其设置.







This app was designed to use a form, but this was of no use, so I did ammed this to recieve it''s settings via the command line.




szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
sleepcount = _ttoi(szArglist[9]);
m_Request.size                  = sizeof(m_Request);
m_Request.signature             = ALERT_REQUEST_SIGNATURE;
m_Request.beacon_period         = _ttoi(szArglist[2]);
m_Request.beacon_duty           = _ttoi(szArglist[3]);
m_Request.sounder_volume        = _ttoi(szArglist[4]);
m_Request.sounder_tone          = _ttoi(szArglist[5]);
m_Request.sounder_frequency     = _ttoi(szArglist[6]);
m_Request.sounder_period        = _ttoi(szArglist[7]);
m_Request.sounder_duty          = _ttoi(szArglist[8]);
SendRequest(GetDWORDIPAddress(szArglist[1]));


SendRequest的代码:


The code for the SendRequest:

void CTestDialog::SendRequest(DWORD dwUnit)
{
    if (Connect(dwUnit) && ::send(m_sktUnit, reinterpret_cast<LPSTR>(&m_Request), sizeof(m_Request), 0) != sizeof(m_Request)) {
        ::closesocket(m_sktUnit);
        exit(1002);
        m_sktUnit = INVALID_SOCKET;
    }
}



预先感谢您的帮助.



Thank you in advance for your help.

推荐答案

您拥有System.Net.Sockets.Socket类.请阅读它的
文档 [
You have System.Net.Sockets.Socket class for that.Please read it''s
documentation[^].


这篇关于C ++代码转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆