C#创建农历引用类库C++调用VB调用

1。创建一个引用微软农历的DLL文件以供C++调用。2022-2-11重新编译修正了闰年月份以及次年月份处理,下载资源

2。修改和加入函数如下: 

3。启动生成后打开文件所在文件夹,复制已经生成好了的DLL文件到C++文件夹内。

 

 4。在C++项目内调用DLL:在我的资源里面提供这个DLL文件下载

#using "..\Debug\农历引用.dll"
using namespace 农历引用;


int _tmain(int argc, _TCHAR* argv[])
{
	系统农历 ^aa = gcnew 系统农历();
	string a = ((CT2A)(CString)(aa->月历加载(2020, 2, 2)));
	cout.put(a[8]).put(a[9]).put(a[10]).put(a[11]) << endl;
	printf_s("%s",(aa->月历加载(2020, 2, 2)));
}

string 返回月历(int 年, int 月, int 日, bool 选 = true)
{
	系统农历^ 农历 = gcnew 系统农历();
	string aa = ((CT2A)(CString)(农历->月历加载(年, 月, 日))), aaa = "";
	aaa.push_back(aa[8]); aaa.push_back(aa[9]); aaa.push_back(aa[10]); aaa.push_back(aa[11]);
	return (选 ? aa : aaa);
}
void 输出万年历(int 年, int 月, int 日)
{
	int r = 1, z = r, nn = 年, yy = 月; string s = "天一二三四五六", aa = " ", aaa = 返回月历(年, 月, 日);
	while (nn)if (--yy)z += 返回月的天数(nn, yy); else --nn, yy = 13;
	nn = 返回月的天数(年, 月); yy = (z + 日 - 1) % 7 * 2;
	cout << 年 << "年" << (月 > 9 ? "" : "0") << 月 << "月" << (日 > 9 ? "" : "0") << 日 << "日"  << "星期"; cout.put(s[yy]).put(s[yy + 1]) << endl;
	cout << "天" << ends << "一" << ends << "二" << ends << "三" << ends << "四" << ends << "五" << ends << "六  ";
	cout << "月历:"; cout.put(aaa[0]).put(aaa[1]).put(aaa[2]).put(aaa[3]);
	cout << "年"; cout.put(aaa[4]).put(aaa[5]).put(aaa[6]).put(aaa[7]).put(aaa[8]).put(aaa[9]).put(aaa[10]).put(aaa[11]) << endl;
	yy = 0;
	while (r <= nn)
	if (yy >= (z %= 7))
	{
		if (r <= 返回月的天数(年, 月)) aa += 返回月历(年, 月, r, false) + " ";
		cout << (r > 9 ? "" : "0") << r++ << ((++yy % 7) ? " " : " ");
		if (yy % 7 == 0){ cout << aa << endl; aa = " "; }
	}
	else
	{
		if (r <= 返回月的天数(年, 月)) aa += (r > 1 ? 返回月历(年, 月, r, false) : "::::") + " ";
		cout << (r > 1 && r <= 9 ? "0" : "") << (r > 1 ? to_string(r++) : "::") << ((++yy % 7) ? " " : " \n");
	}
	cout << endl;
}
void 输出万年历(int 年, int 月, int 日)
{
	int r = 0, z = 1, nn = 年, yy = 月; string s = "天一二三四五六", aa = " ", aaa = 返回月历(年, 月, 日);
	while (nn)if (--yy)z += 返回月的天数(nn, yy); else --nn, yy = 13;
	nn = 返回月的天数(年, 月); yy = (z + 日 - 1) % 7 * 2;
	cout << 年 << "年" << (月 > 9 ? "" : "0") << 月 << "月" << (日 > 9 ? "" : "0") << 日 << "日"  << "星期";
	cout.put(s[yy]).put(s[yy + 1]) << endl;
	cout << "天" << ends << "一" << ends << "二" << ends << "三" << ends << "四" << ends << "五" << ends << "六  ";
	cout << "月历:"; cout.put(aaa[0]).put(aaa[1]).put(aaa[2]).put(aaa[3]);
	cout << "年"; cout.put(aaa[4]).put(aaa[5]).put(aaa[6]).put(aaa[7]).put(aaa[8]).put(aaa[9]).put(aaa[10]).put(aaa[11]) << endl;
	z %= 7; if (z)yy = 返回月的天数(年 - (月 == 12 ? 1 : 0), 月 == 12 ? 月 : --月) - z; else yy = 0;
	while (r < 42)
	{
		if (++yy>返回月的天数(年, 月))++月, yy = 0;
		else
		{
			cout << (yy > 9 ? "" : "0") << yy << ends, aa += 返回月历(年, 月, yy, false) + " ";
			if (++r % 7 == 0)cout << aa << endl, aa = " ";
		}
	}
	cout << endl;
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 农历引用
{
    public class 系统农历
    {
        public static string 月历加载(int 查年, int 查月, int 查日)
        {
            System.Globalization.ChineseLunisolarCalendar 微软农历 = new System.Globalization.ChineseLunisolarCalendar();
            int 天 = 微软农历.GetDayOfMonth(new DateTime(查年, 查月, 查日)),
            月 = 微软农历.GetMonth(new DateTime(查年, 查月, 查日)),//DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day
            年 = 微软农历.GetSexagenaryYear(DateTime.Parse(查年.ToString("0年") + 查月.ToString("0月") + 查日.ToString("0日")))
            , 闰月 = 0;
            if (微软农历.IsLeapYear(查年)) while (微软农历.IsLeapMonth(查年, ++闰月) == false && 闰月 < 12) ;
            if (微软农历.IsLeapYear(查年 - 1)) while (微软农历.IsLeapMonth(查年 - 1, ++闰月) == false && 闰月 < 12) ;

            if ((微软农历.IsLeapYear(查年) && 月 >= 闰月 && 月 < 12) || (微软农历.IsLeapYear(查年 - 1) && (月 == 12 || 月 == 13)))
                --月;

            return "月历:" + "◇甲乙丙丁戊己庚辛壬癸"[微软农历.GetCelestialStem(年)]
                + "¤鼠牛虎兔龙蛇马羊猴鸡狗猪"[微软农历.GetTerrestrialBranch(年)] + "年"
                + "◎春梅桃麦仲荷瓜桂菊露冬腊"[月] + (天 > 10 ? "月" : "月初") + ("□十廿仨"[天 / 10]).ToString().Replace("□", "")
                + "〇一二三四五六七八九"[天 % 10];
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值