vc做的供其他语言调用的dll的例子 (传递的是字符串格式的参数)
2012-11-08 17:09
543 查看
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();
}
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();
}
相关文章推荐
- 在VB中调用C/C++语言编写的dll,数组参数的传递
- C# 调用Dll 传递字符串指针参数 .
- vc 调用delphi DLL ,传字符串参数
- 在VB中调用C/C++语言编写的dll,数组参数的传递
- C# 调用Dll 传递字符串指针参数
- 用C#调用C++DLL时的字符串指针参数传递问题
- C# 调用Dll 传递字符串指针参数
- windows下,python调用dll例子,展示如何传递字节码流参数到dll接口
- 易语言dll中文本型参数或返回值在其他语言中调用异常问题
- 关于 php 调用 其他语言写的Web Service SOAP 接口的参数传递问题
- 一个内核模块例子(实现调用其他模块中的方法,传递参数等)
- 在VB中调用C/C++语言编写的dll,数组参数的传递
- C# 调用Dll 传递字符串指针参数
- C#中调用其他语言写的DLL
- ARM汇编语言调用C函数之参数传递
- C#调用VC DLL接口函数参数类型转换方法介绍
- arm汇编语言调用C函数之参数传递
- C# 调用 C++ dll 函数 时传递字符串 需要注意的问题
- STL 不同版本DLL调用参数传递失败
- 总结VC与易语言DLL互相调用的方法