设为首页 加入收藏

TOP

vc做的供其他语言调用的dll的例子 (传递的是字符串格式的参数)
2012-12-02 22:33:07 】 浏览:468
Tags:其他 语言 调用 dll 例子 传递 字符串 格式 参数

VC  工程

char* p = NULL;

extern "C" _declspec(dllexport)
char*   _stdcall  output_number(char* aa)
{

 CString s = aa;
 s += "abcd";
 
 int nlen = s.GetLength();
 if(p != NULL)
 {
  delete[] p;
  p = NULL;
 }
 p = new char[nlen + 1];
 
 p[nlen] = 0;
 
 memcpy(p,s.GetBuffer(0),s.GetLength());
 
 
 
 return p;

 
}
extern "C" _declspec(dllexport)
void _stdcall   deleteaa()
{
 if(p != NULL)
 {
  delete[] p;
  p = NULL;
 }
}

调用方:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication4
{
    public static class Class1
    {
        [DllImport("pb.dll")]
        public static extern string output_number(  string str);

 


        [DllImport("pb.dll")]
        public static extern void deleteaa();
    }
}

 

  string aaa;
        //char* aaa;
        private void button1_Click(object sender, EventArgs e)
        {
            string s = "256\0";
            aaa =  Class1.output_number("2567");
            MessageBox.Show(aaa);
           

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Class1.deleteaa();
        }

 

 

 

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇关于MFC下检查和消除内存泄露的技.. 下一篇CString & 类型和引用

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目