Git Product home page Git Product logo

csharpgodemo's Introduction

介绍

  • 基本MVVM代码结构、包括Command绑定控件

  • 实现单例模式

  • 实现C#驱动Go项目

  • View:

    • MordenWPF美化控件
    • Hardcodet实现WPF系统托盘效果
      • 代码实现图标闪烁

CSharp using Go

package main

import (
	"C"
	"zggsong.cn/scadatool/server"
)

func main() {
	run()
}

//export run
func run() string {
	// 启动服务
	server.StartServer()
	return "success"
}
/// <summary>
/// 引入Go项目库
/// </summary>
/// <returns></returns>
[DllImport("scadatool_go.dll", EntryPoint = "run")]
extern static GoString run();

#本项目中的代码示例
string result = GoCSharpHelper.Instance().GoStringToCSharpString(run());

Go字符串乱码问题

/// <summary>
/// 转换Go string类型为C# String
/// </summary>
public struct GoString
{
	public IntPtr p;
	public int n;
	public GoString(IntPtr n1, int n2)
	{
		p = n1; n = n2;
	}
}
public string GoStringToCSharpString(GoString goString)
{
	byte[] bytes = new byte[goString.n];
	for (int i = 0; i < goString.n; i++)
	{
		bytes[i] = Marshal.ReadByte(goString.p, i);
	}
	string result = Encoding.UTF8.GetString(bytes);
	return result;
}

csharpgodemo's People

Contributors

zggsong avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.