string类型函数 bcb做dll,c#调用

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());
        }
    }
}

posted @ 2010-04-15 12:40  meetrice  阅读(600)  评论(0编辑  收藏  举报