使用C函数作为C ++类方法 [英] using C function as C++ class method

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

问题描述

您好,



我有一个没有课程的C函数。它只是头文件中的一个函数。



我想将它作为托管代码公开,所以我创建了一个新的C ++文件,它有



  extern    C 
{
#include < span class =code-string> cfile.h
}

< span class =code-keyword> public ref class managedClass
{
public
/// //我想从cfile.h公开函数
}



所以我可以使用C#中的托管代码,如



 var test = managedClass.functionName(,,); 

解决方案

您只需要在成员函数中调用c-func。但你最好在它周围做一些错误检查。



如果你将dll与delayload链接起来,你将获得一些启动好处。


Hello,

I have a C function without a class. its just a function in a header file.

I want to expose it as managed code, so i am creating a new C++ file which had

extern "C"
{
    #include "cfile.h"
}

public ref class managedClass
{
    public:
         ///// I want to expose the function from cfile.h
}


So i can use the managed code in C# like

var test = managedClass.functionName(,,);

解决方案

you only need to call the c-func in a member function. But you better do some error checking around it.

If you link the dll with "delayload" you will get some startup benefit.


这篇关于使用C函数作为C ++类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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