从C#调用C函数 [英] Call C function from C#

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

问题描述

我正在构建一个应用程序,我需要在c#中集成动态链接库运行时。我在从C#调用一个C函数时遇到问题。



DLL函数:



I am building an application where I need to integrate Dynamic Link Library runtime in c#. I am facing problem in calling one C function from C#.

DLL Function:

typedef void *JCCP_PROPERTY_HANDLE;
typedef void *JCCP_HANDLE;

JCCP_RESULT  __JCCP_FUNCTION__ jccpGetProperty(
    JCCP_HANDLE hjccp,
    const char *name,
    JCCP_PROPERTY_HANDLE *phproperty);





函数定义文件:





In Function Definition File:

_jccpGetProperty @49



用法 - 例如:




Usage- C example:

JCCP_HANDLE m_hjccp = jccpAllocateHandle();
JCCP_PROPERTY_HANDLE hprop;
jccpGetProperty(m_hjccp, name, &hprop);

如果此函数成功执行,则返回0.



现在我想在C#中调用这个函数(jccpGetProperty),但是我不知道如何在C#中调用这个函数。



我到目前为止尝试过:



声明:



If this function executes successfully, It return 0.

Now I want to call this function (jccpGetProperty) in C#, but I dont know how to call this function in C#.

I have tried so far:

Declaration:

IntPtr hjccp;

     [DllImport(DLL_NAME, EntryPoint = "_jccpAllocateHandle", CallingConvention = CallingConvention.Cdecl)]

     [DllImport(DLL_NAME, EntryPoint = "_jccpGetProperty", CallingConvention = CallingConvention.Cdecl), UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public static extern IntPtr jccpGetProperty(IntPtr hjccp, string name, ref IntPtr handle);

主要功能:



In Main Function:

hjccp = jccpAllocateHandle();
IntPtr handle = IntPtr.Zero;
var result = jccpGetProperty(hjccp, "tag", ref handle);

我没有得到任何异常,但我没有得到0作为回应,我得到17回应这是请求丢弃的代码。任何人都可以指导我如何在C#中正确调用jccpGetProperty()吗?

我很困惑我怎么能通过C#将第三个参数发送到jccpGetProperty函数。



谢谢。

I dont get any exception but I dont get 0 in response, I get 17 in response which is request discarded code. Can anybody guide me that how to call jccpGetProperty() in C# properly?
I am confused that how can I send third parameter to jccpGetProperty function through C#.

Thanks.

推荐答案

试试这个链接:



https://msdn.microsoft.com/en-us/library/26thfadc(v = vs.110 ).aspx [ ^ ]



希望有所帮助
Try this link:

https://msdn.microsoft.com/en-us/library/26thfadc(v=vs.110).aspx[^]

Hope it helps


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

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