接口转换问题,懂C/C++的高手请进

Robinsonzhan Robinsonzhan 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
C#中如何调用C的接口(.h和.lib文件),直接添加.lib引用是不行的,是不是需要转换成DLL成类库或者其他什么的,还有其他方法吗?
如需转换,以下是C的头文件:(如需更详细,请留下e-mail,我发文件过去)

#ifndef ASR_CLIENT_H
#define ASR_CLIENT_H

#ifdef __cplusplus
extern "C" {
#endif

enum ASR_WAV_FORMAT {
WAV_FORMAT_ULAW, /* MU-law */
WAV_FORMAT_ALAW, /* A-LAW */
WAV_FORMAT_LPCM /* linear pcm */
};

enum ASR_STATUS {
ASR_SUCCESS = 0, /* function is called successfully */
ASR_EINTERNAL, /* internal error */
ASR_EFILE, /* file error */
ASR_EMEM, /* out of memory */
ASR_ENETWORK, /* network/socket errors */
ASR_EINVAL, /* invalid parameters */
ASR_EOVERFLOW, /* buffer too small */
};

typedef struct asr_result_t{
int n; /* number of n-best result */
char output[5][512]; /* top 5 result */
char score[5][12]; /* top 5 score */
char aux[2048]; /* aux */
} asr_result;

/**
* Initialize the ASR client module
* @param host the host name
* @param port the port on host
* @return ASR_STATUS
*/
int asr_init(const char* host, int port);

/**
* Finalize the ASR client module
*/
void asr_final();

/**
* Request the ASR server to generate resources
* @param class_name the name of the resources
* @param enc the encoding type of the buffer (e.g. gb2312, utf-8)
* @param buf the buffer of the words list.
* The words are seperated by the new line.
* @param size the size of the buffer
* @return ASR_STATUS
*/

int asr_gen(const char* class_name,
const char* enc, const char* buf, int size);

/**
* asr_t is a handle to a asr client
* It is obtained by asr_open()
* and used in asr_write(), asr_read() and asr_close()
*/
typedef struct asr_t asr_t;


/**
* Decode a file. A shortcut from invoking asr_open, asr_write,
* asr_read, and asr_close in sequence.
* @param class_name the name of the resources to be used for decoding
* @param fname the name of a file containing wave data to be decoded
* @param wavfmt the format of the wave data in file passed in
* @param result_buf return the result of the decoding
* @param result_bufsz size of the result_buf
* @param aux_buf is aux data of previous wave
* @return ASR_STATUS
*/
int asr_decode(const char* class_name,
const char* fname,
int wavfmt,
char* result_buf,
int result_bufsz,
char* aux_buf);



/**
* Open and start a new asr session
* @param asr return an asr handle
* @param class_name the name of the resources to be used for decoding
* @param wavfmt the format of the wave data in file passed in
* @return ASR_STATUS
*/
int asr_open(asr_t** asr, const char* class_name,
int wavfmt);

/**
* Sets the aux info of this asr session. The Aux info is embedded in the
* results of the previous asr decoding session. The ASR stores some auxiliary
* information in the Aux info that uses characteristics of the previous
* decoding session to help in improving the accuracy of this session. The use
* of the aux info is completely optional, but you are encouraged to supply
* this info if available.
*
* @param asr the asr handle
* @param aux the aux info
* @return ASR_STATUS
*/
int asr_set_aux(asr_t* asr, const char* aux);

/**
* Send a block of data to the ASR server. Each block should be less
* than 4 Kbytes in size.
*
* @param asr the asr handle
* @param buf the buffer of the wave data
* @param size the size of the buffer
* @param result_pending 0 if result is not ready, non-zero otherwise
* @return ASR_STATUS
*/
int asr_write(asr_t* asr, const char* buf, int size, int *result_pending);


/**
* Read the result from the ASR server
* @param asr the asr resource handle
* @param asr_result the result returned by the ASR server
* @return ASR_STATUS
*/
int asr_read(asr_t* asr, char** asr_result);

/**
* Close the asr client handle
* @param asr the asr handle
* @return ASR_STATUS
*/
void asr_close(asr_t* asr);

#ifdef __cplusplus
}
#endif

#endif
...全文

相关推荐

c/c++采用编码转换表实现gbk与unicode互转

c/c++采用编码转换表实现gbk与unicode互转,文件内含有两个编码大矩阵, 采用unicode小端模式,程序简单易懂

bladeandmaster88

cpp-易盛接口托管C封装

易盛接口托管C 封装(当前只封装了外盘接口,实用易盛外盘3.0接口)

weixin_39841848

J2cpp-Java到C++的转换工具

J2cpp 是一个 Eclipse 的插件,可以将 Java 类转为 C++11 类。需要注意的是生成的 C++ 代码在进行转换处理之前是没法编译的,你必须对生成的代码进行二次处理。 安装地址:http://tsug.github.com/j2cpp/update/ 转换示例:http://www.oschina.net/code/snippet_12_12650

岭上花

JNI技术手册 c/c++调用java

目录 I. 目录 1 II. java c/cpp互相调用实例(姊妹篇之一)——java调用c/cpp 4 一 先制作一个系统中有的DLL文件(cpp给出的sdk接口) 4 二 JNI 7 1、 编写java文件 7 2、 生成.h头文件 8 3、 用c/cpp实现这个头文件 9 三 测试 10 四 最后补充 11 III. java c/cpp互相调用实例(姊妹篇之二)——c/cpp调用java 11 一、 编写java代码 12 二、 编译java代码 12 三、 编写 C/C++ 代码 13 四、 运行exe 18 IV. Java JNI 编程进阶 18 一、 解决性能问题 18 二、 解决本机平台接口调用问题 19 三、 嵌入式开发应用(JNI小例子) 20 1、 新增一个基础类 22 2、 定义新类继承基础类 23 3、 编写调用类 23 4、 新增两个本地方法 24 5、 修改 RunMain 类 25 6、 新增一个方法处理java对象 26 7、 新增一个方法处理数组 29 8、 改写RunMain 32 四、 参考资料: 33 V. Eclipse+CDT+MinGW 进行JAVA调用C/C++ 34 一、 安装eclipse3.2。 34 二、 安装MinGW。 34 1、 下载MinGW 34 2、 安装 34 3、 安装版本 34 4、 选择安装的编译器 34 5、 选择安装路径,下一步 35 6、 等待下载软件 35 三、 MinGW的环境变量设置 35 1、 设置Path 35 2、 设置C_INCLUDE_PATH 35 3、 设置CPLUS_INCLUDE_PATH 35 四、 做一个小技巧修改 35 五、 安装CDT插件 36 1、 下载CDT插件 36 2、 安装CDT插件 36 六、 简单介绍CDT的使用吧 36 1、 新建一个C++项目 36 2、 输入New Project名字 36 3、 给项目新建一个的源文件 36 4、 接着出现文件添加的窗口,在File Name栏里面写上文件名 36 5、 编辑hello.cpp 37 6、 添加一个编译命令 37 七、 让我们开始进入真正的工作吧! 38 The Java side 38 1、 建立Java工程JavaHello,编写java类 38 2、 用命令生成头文件 38 The C side-Compiling the Library 40 1、 建立标准C工程Cpro,并生成dll文件 40 1) 将生成的头文件test_Hello.h拷贝到C工程Cpro下 40 2) 编写C类Hello.c,内容为: 40 3) 在C工程Cpro下建立hello.def文件(用于定义导出的函数),内容为: 40 4) 在C工程Cpro下建立makefile文件,内容为: 40 5) Make Targets 40 6) Make Targets视图下双击step1,在C工程Cpro下生成hello.o 文件。 41 7) Make Targets视图下双击step1,在C工程Cpro下生成hello.dll 文件。 41 2、 JAVA调用DLL 41 1) 将hello.dll拷贝到Java工程JavaHello下。 41 2) 运行Hello.java,则可以看到输出结果: 41 1) 将Hello.c改为Hello.cpp 41 2) 将makefile内容改为: 41 3) 其他的几乎都不用改变也可以。 42 评论: 42 VI. c++如何调用java程序 51 DemoMain.java内容如: 51 采用vc6++ IDE,采用JNI技术实现。 51 1、 编译时 51 2、 运行时 51 程序的关键在 53 VII. JNI 53 一、 定义 53 二、 设计目的 54 三、 书写步骤 54 1) 编写java程序:这里以HelloWorld为例。 54 2) 编译 55 3) 生成扩展名为h的头文件 55 4) 编写本地方法实现和由javah命令生成的头文件里面声明的方法名相同的方法。 56 5) 生成动态库 56 6) 运行程序 java HelloWorld就ok. 56 四、 调用中考虑的问题 56 1) java和c是如何互通的? 57 2) 如何将java传入的String参数转换为c的char*,然后使用? 57 3) 将c中获取的一个char*的buffer传递给java? 57 4) 不知道占用多少空间的buffer,如何传递出去呢? 58 五、 对JAVA传入数据的处理 58 1) 如果传入的是bytearray的话,作如下处理得到buffer: 58 VIII. C/C++调用JAVA类 58 一、 加载虚拟机: 59 二、 获取指定对象的类定义: 59 三、 获取要调用的方法: 59 四、 调用JAVA类方法: 60 五、 获得类属性的定义: 60 六、 数组处理: 60 七、 异常: 60 八、 多线程调用 61 Java代码 61 命令行运行:javap -s -p MyTest ,输出: 62 C代码testjava.c: 62 编译: 65 运行结果: 65

老黄忠

C#调用C++ Api或接口转换工具

C#调用C++ Api或接口转换工具,自动将C++ Api转换成C#中使用接口 开发C#调用C++库或者api的好助手。

初小猫
评论 16
收藏 已收藏
分享
返回顶部
Robinsonzhan
C# 111,129 成员 642,540 内容