从C#调用dll方法 [英] Calling dll method from C#

查看:67
本文介绍了从C#调用dll方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我在c#上有这个方法。

哪种方法可以调用它?





 [System.Runtime.InteropServices.DllImportAttribute(  QCamDriver.dll,CallingConvention=CallingConvention.StdCall,EntryPoint =   QCam_ListCameras)] 
< span class =code-keyword> public static extern QCam_Err QCam_ListCameras( ref QCam_CamListItem pList, ref uint pNumberInList);

解决方案

如果您正在调用托管代码,那么



 Assembly SampleAssembly = Assembly.LoadFrom(filename); 
输入myType = SampleAssembly.GetTypes()[0];
MethodInfo Method = myType.GetMethod(myVoid);
object myInstance = Activator.CreateInstance(myType);
Method.Invoke(myInstance,null);





如果你打电话给非托管代码那么



从C#中用C编译的Dll调用方法 [ ^ ]


Hello, I have this method at c#.
Which is the right way to call it?


[System.Runtime.InteropServices.DllImportAttribute("QCamDriver.dll",CallingConvention=CallingConvention.StdCall,EntryPoint = "QCam_ListCameras")]
            public static extern QCam_Err QCam_ListCameras(ref QCam_CamListItem pList, ref uint pNumberInList);

解决方案

if you are calling the managed code then

 Assembly SampleAssembly = Assembly.LoadFrom(filename);
Type myType = SampleAssembly.GetTypes()[0];
MethodInfo Method = myType.GetMethod("myVoid");
object myInstance = Activator.CreateInstance(myType);
Method.Invoke(myInstance, null); 



and if you are calling unmanaged code then

Calling methods from Dll compiled in ''C'' from C#[^]


这篇关于从C#调用dll方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆