How to use C++ code in C#

Why cannot use C++ code in C# directly?

The most remarkable difference between C++ and C# ,i think ,is C++ is unmanaged language rather C# is managed ,which determined you can not write C++ code into the C# code directly,otherwise ,unmanaged code will seems like a runaway train in the managed code

How many ways to use C++ code in C#?

in my opinion ,the ways to use C++ code in C# depends on what you want to call.i just briefly list two type that you want call:

  • C++ function
  • C++ Class
Call C++ function by using Platform Invocation(PInvoke)

PInvoke allows for managed code to call native unmanaged functions implemented as DLLs.this method is ideal for when we have API-like function written in C or C++ that need to be accessed from within a C# program.

NOTE:PInvoke only can be used to Marshall function not to CLass.

The diagram below summarise the PInvake mechanism.

A PInvoke example

Step1 : create Dll project

there is a link aboutcreate DLL project in VS2017

Continue reading “How to use C++ code in C#”

compile Aliyu OSS C++ SDK in windows and install on VS2017

Step0 Downloadthe SDK

there is a official Link about

how to install the SDK in linux and windows

that also include the Download link.

it seems like that the folder which you downlode from github have the suffix of master.

The alibabacloud-oss-cpp-sdk.sln project file is not included in the downloaded SDK package. You must run the cmake command to generate the required project file

step1 intall the cmake

  • Install cmakeOpen cmd to go to the directory that stores the SDK files, create a folder named build, and run cmake to generate the required files, as shown in the following figure
Continue reading “compile Aliyu OSS C++ SDK in windows and install on VS2017”

网络编程

友情链接:Tcp的3次握手与4次分手
ICMP 协议: 电脑之间相互Ping时用的协议

以太网帧


ARP协议(解决目的物理地址的问题,链路层)

Pc1发一个ARP请求包,FFFFF为群发,
当PC2发现目的IP地址和自己相同时,接受,回一个应答包,应答包中含有自己的物理地址,也不是每次同信都要先发送一个ARP请求包,每个主机都有一个ARP映射表。
图中交换机工作在链路层,并没有涉及IP,只是获取解析出物理地址

抓包工具
WireShark

IP协议(网络层,不可靠协议)
TCP协议(传输层,连接的,可靠的 流协议)
UDP(传输层,无连接的,不可靠的,数据包协议)

ping的时候是发了个ICMP的数据包,属于网络层(ICMP、IGMP、IP、)
ICMP(判断2台主机是否同信)

路由器主要是解析计算IP地址,下一跳是哪一步,提供路由算法,工作在网络层,

交换机,负责以太网帧的目的地址来决定以太网帧发给谁,(工作在链路层)。

大端字节序:高字节在底地址,低字节在高地址
小端字节序:高字节在高地址,底字节在底地址 x86
判断大端序还是小端序