问劫出新装备很适合他把
-
彡木啊
第一步,我先从简单的调用出发,定义了一个简单的函数,该函数仅仅实现一个整数加法求和:
libexport_api int mysum(int a,int b){ return a+b;}
c# 导入定义:
public class refcomm
{
[dllimport("libencrypt.dll",
entrypoint="mysum",
charset=charset.auto,callingconvention=callingconvention.stdcall)]
public static extern int mysum(int a,int b);}
在c#中调用测试:
int **um=refcomm.mysum(,);运行查看结果**um为5,调用正确。第一步试验完成,说明在c#中能够调用自定义的动态链接库函数。第二步,我定义了字符串操作的函数(简单起见,还是采用前面的函数名),返回结果为字符串:
libexport_api char*mysum(char*a,char*b){sprintf(b,"%s",a);return a;}
c# 导入定义:
public class refcomm
{
[dllimport("libencrypt.dll",
entrypoint="mysum",
charset=charset.auto,
callingconvention=callingconvention.stdcall)]
public static extern string mysum(string a,string b);}
在c#中调用测试:
string strdest=";string strtmp=refcomm.mysum("45",strdest);运行查看结果 strtmp 为"45",但是strdest为空。我修改动态链接库实现,返回结果为串b:
libexport_api char*mysum(char*a,char*b){sprintf(b,"%s",a)return b;}
修改 c# 导入定义,将串b修改为ref方式:
public class refcomm
{
[dllimport("libencrypt.dll",
entrypoint="mysum",
charset=charset.auto,callingconvention=callingconvention.stdcall)]
public static extern string mysum(string a,ref string b);}
在c#中再调用测试:
string strdest=";string strtmp=refcomm.mysum("45",ref strdest);运行查看结果 strtmp 和 strdest 均不对,含不可见字符。再修改 c# 导入定义,将charset从auto修改为ansi:
public class refcomm
{
[dllimport("libencrypt.dll",
entrypoint="mysum",
charset=charset.ansi,callingconvention=callingconvention.stdcall)]
public static extern string mysum(string a,string b);}
在c#中再调用测试:
string strdest=";string strtmp=refcomm.mysum("45",ref strdest);运行查看结果 strtmp 为"45",但是串 strdest 没有赋值。第二步实现函数返回串,但是在函数出口参数中没能进行输出。再次修改 c# 导入定义,将串b修改为引用(ref):
public class refcomm
{
[dllimport("libencrypt.dll",
entrypoint="mysum",
charset=charset.ansi,callingconvention=callingconvention.stdcall)]
public static extern string mysum(string a,ref string b);}
运行时调用失败,不能继续执行。第三步,修改动态链接库实现,将b修改为双重指针:
libexport_api char*mysum(char*a,char*b){sprintf((*b),"%s",a);return*b;}
c#导入定义:
public class refcomm
{
[dllimport("libencrypt.dll",
entrypoint="mysum",
charset=charset.ansi,callingconvention=callingconvention.stdcall)]
public static extern string mysum(string a,ref string b);}
在c#中调用测试:
string strdest=";string strtmp=refcomm.mysum("45",ref strdest);运行查看结果 strtmp 和 strdest 均为"45",调用正确。第三步实现了函数出口参数正确输出结果。第四步,修改动态链接库实现,实现整数参数的输出:
libexport_api int mysum(int a,int b,int*c){*c=a+b;return*c;}
c#导入的定义:
public class refcomm
{
[dllimport("libencrypt.dll",
entrypoint="mysum",
charset=charset.ansi,callingconvention=callingconvention.stdcall)]
public static extern int mysum(int a,int b,ref int c);}
在c#中调用测试:
int c=0;int **um=refcomm.mysum(,ref c);运行查看结果**um 和c均为5,调用正确。经过以上几个步骤的试验,基本掌握了如何定义动态库函数以及如何在 c# 定义导入,有此基础,很快我实现了变长加密函数在 c# 中的调用,至此目标实现。三、结论
在 c# 中调用 c++ 编写的动态链接库函数,如果需要出口参数输出,则需要使用指针,对于字符串,则需要使用双重指针,对于 c# 的导入定义,则需要使用引用(ref)定义。对于函数返回值,c# 导入定义和 c++ 动态库函数声明定义需要保持一致,否则会出现函数调用失败。定义导入时,一定注意 charset 和 callingconvention 参数,否则导致调用失败或结果异常。运行时,动态链接库放在 c# 程序的目录下即可,我这里是一个 c# 的动态链接库,两个动态链接库就在同一个目录下运行。
-
问 lol新装备哪些适合贾克斯
提问时间:2024-05-06 17:20:56
答 不如体验竞技游戏推荐王.牌对决竞技游戏爽朗对战全明星动作对战网游王牌对决上线混战**足球**和豪绅**三大新**,以及三大神之使者系列英雄梵**拳,荒漠冥神和堕...
-
问 lol新装备石像鬼石板甲,最适合哪个位置出
提问时间:2024-05-06 12:33:44
答 总花费:2500金币合成路线:锁子甲+负极斗篷+980金币护甲:40魔抗:40唯一被动-石肤:当附近有3位以上敌方英雄存在时,获得40额外护甲和魔抗唯一主动-金
-
问 英雄联盟那些英雄出新装备适合
提问时间:2024-05-06 10:42:06
答 **英雄:劫 螳螂 狮子 泰隆。b级英雄:盲僧 猴子 锐雯 嘉文 梦魇 潘森 小丑。c级英雄:蔚 亚索 奎因 赵信 杰斯 薇恩 老鼠
-
问 英雄联盟时光出什么装能减40cd,适合他的装备
提问时间:2024-05-06 05:04:35
答 时光不需要40的减cd,他的w技能是天生的减cd装备,我个人觉得时光有25%左右的减cd就可以了,依靠w刷新qe,可以一直保持快速移动和q放**,他前期比较缺蓝...
-
问 有哪些炼金装备适合新手
提问时间:2024-05-06 02:02:53
答 一、如果你的佣兵已经洗好技能:最佳推 无忧巛奇:大毒、晕眩、隐身、小毒。因为大毒放最前面,那么最大可能的在少回合里多输出伤害。先晕眩,再隐身,就给猎人加大生存的...
-
问 lol寒冰如何出装 适合新手的
提问时间:2024-05-06 23:55:13
答 多兰出门 或者一鞋3红 拼命懒线打钱核心装 无尽 红叉 这两个尽早出,但是可以先用着黄叉,因为移动已经到了400 够用。无尽优先级大于黄叉,实在不行用风暴加黄叉...
-
问 哪本吉他教材适合新手?
提问时间:2024-05-06 00:38:02
答 《吉他自学三月通》讲得很广也很浅,既讲了弹唱也讲了指弹技巧。主要是教初学者对吉他的基本认识,比如音阶、简单**、拨片,和各种风格的(蓝调啊什么的都有练习)…《指...