BCB:
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
extern "C" __declspec(dllexport) char* importStr(AnsiString str1)
{
return str1.c_str(); //把AnsiString转换为char*,返回char*类型
}
C#:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
[DllImport("C:\test.dll")]
public static extern StringBuilder _importStr(String str1);
static void Main(string[] args)
{
Console.WriteLine(_importStr("hello world1").ToString());
}
}
}