zoukankan      html  css  js  c++  java
  • 基于GDAL提取地物,并生成png,最后加载到网页上(二)

    C# 调用 C++ DLL  的struct 传递

    C++  .h

    #pragma once
    typedef struct
    {
    	int nAge;
    	bool bUse;
    	double nDistance;
    	char name[200];
    }LIDBATATYPE;
    
    typedef struct
    {
    	int progress;
    	char msg[100];
    }OUTMSG;
    
    extern "C" _declspec(dllexport) int _stdcall PassStruct(LIDBATATYPE *mdata); //指针
    extern "C" _declspec(dllexport) int _stdcall sendMsg(OUTMSG &msg);           //引用
    

    C++ cpp

    int _stdcall PassStruct(LIDBATATYPE *mdata)
    {
    	
    	int age = mdata->nAge;
    	bool use = mdata->bUse;
    	double distance = mdata->nDistance;
    	std::string n = mdata->name;
    	mdata->nAge = 101;
    	int a = age + 1;
    	return a;
    	
    }
    int _stdcall sendMsg(OUTMSG &msg)
    {
    	int pro = msg.progress;
    	msg.progress = 123;
    	//msg.msg = "cppmsg";
    	std::string str = "cppmsg";
    	//strcpy(msg.msg, str.c_str());
    	//str.copy(msg.msg, 7, 0);
    	int i;
    	for ( i = 0; i < str.length(); i++)
    	{
    		msg.msg[i] = str[i];
    	}
    	msg.msg[i] = '';
    	//printf("%s
    ", p);
    	return msg.progress;
    
    }
    

      

    [StructLayout(LayoutKind.Sequential,CharSet =CharSet.Ansi)]
    public  struct OUTMSG
    {
        public int progress;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string msg;
    }
    public struct toCppData
    {
        public int nAge;
        public bool bUse;
        public double nDistance;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 200)]
        public string name;
    }
    
           [DllImport(@"../../../Debug/CreateDLL.dll", EntryPoint = "test01", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
            extern static int test01(int a, int b, int c);
    
            [DllImport(@"../../../Debug/CreateDLL.dll", EntryPoint = "test02", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
            extern static int test02(int a, int b);
          
            [DllImport(@"../../../Debug/CreateDLL.dll", EntryPoint = "ReadRaster", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
            extern static int ReadRaster();
           
            [DllImport(@"../../../Debug/CreateDLL.dll", EntryPoint = "PassStruct", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
            extern static int PassStruct(ref toCppData _data);
    
            [DllImport(@"../../../Debug/CreateDLL.dll", EntryPoint = "sendMsg", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
            extern static int sendMsg(ref OUTMSG msg);
    
            static void Main(string[] args)
            {
                //int r1 = test01(1, 2, 3);
                //int r2 = test02(5, 2);
                // int r3 = ReadRaster();
                // Console.WriteLine("test01结果:" + r3.ToString());
                //Console.WriteLine("test02结果:" + r2.ToString());
    
                toCppData data = new toCppData();
                data.nAge = 100;
                data.bUse = false;
                data.nDistance = 3.1415926;
                data.name = "abcd";
                int v = PassStruct(ref data);
    
                OUTMSG mMsg = new OUTMSG();
                mMsg.progress = 999;
                int ret = sendMsg(ref mMsg);
                int progress = mMsg.progress;
                Console.WriteLine("结果:" +mMsg.msg.ToString());
    
    
                Console.ReadKey();
            }
    

      

  • 相关阅读:
    2019-2020-1 20175335 20175303 20175304 20275327 实验三 并发程序
    2019-2020-1 20175304 20175303 20175327 20175335 实验二 固件程序设计
    2018-2019-1 20175304 20175303 20175327 20175335 实验一 开发环境的熟悉
    2019-2020-1 20175312 20175333 实验四 外设驱动程序设计
    实验三 并发程序
    2019-2020-1 20175312 20175321 20175333 实验三-并发程序
    2019-2020-1 20175312 20175321 20175333 实验二 固件程序设计
    2019-2020-1 20175312 20175321 20175333 实验一 开发环境的熟悉
    # 2019-2020-1 20175333曹雅坤 《信息安全系统设计基础》第四周学习总结
    2019-2020-1 20175333《信息安全系统设计基础》第三周学习总结
  • 原文地址:https://www.cnblogs.com/marky/p/11417129.html
Copyright © 2011-2022 走看看