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

Robinsonzhan 2004-12-03 09:55:56
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
...全文
153 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
cppTrier 2005-01-05
  • 打赏
  • 举报
回复
先编译成DLL(不需要是COM组件),然后用P/Invoke调用就可以了。
Robinsonzhan 2005-01-05
  • 打赏
  • 举报
回复
MyNameEPC 2004-12-13
  • 打赏
  • 举报
回复
把文件编译成一个 DLL,这样就可以使用了,就像调用 Windows API 一样,使用 System.Runtime.InteropServices 就可以了,MSDN 和网上有很多关于 Interop 的。另外,如果不是 COM 的话,没有必要封装成 COM 再使用。
x0000 2004-12-13
  • 打赏
  • 举报
回复
晕,查看命令的帮助
Robinsonzhan 2004-12-13
  • 打赏
  • 举报
回复
自己顶!
Robinsonzhan 2004-12-04
  • 打赏
  • 举报
回复
怎么写啊?
Robinsonzhan 2004-12-03
  • 打赏
  • 举报
回复
是啊,只有VC++可以,就是问怎么转换啊
kangxidadi 2004-12-03
  • 打赏
  • 举报
回复
在.net别想直接使用.lib,你还是连接成.dll之后用importdll调用吧。
Robinsonzhan 2004-12-03
  • 打赏
  • 举报
回复
多谢!
xiaoslong 2004-12-03
  • 打赏
  • 举报
回复
帮你顶
xiaoslong 2004-12-03
  • 打赏
  • 举报
回复
帮你顶一下
Robinsonzhan 2004-12-03
  • 打赏
  • 举报
回复
或者MSN:zhanfalong@hotmail.com
谢谢!
Robinsonzhan 2004-12-03
  • 打赏
  • 举报
回复
本人e-mail:Robinsonzhan@126.com
改好了,给我发邮件,一定给分。先谢了。
x0000 2004-12-03
  • 打赏
  • 举报
回复
使用类型库导出工具,生成一个com组件,然后加为.net引用,详细用法及其参数如下:
Microsoft (R) .NET Framework Type Library to Assembly Converter 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Syntax: TlbImp TypeLibName [Options]
Options:
/out:FileName File name of assembly to be produced
/namespace:Namespace Namespace of the assembly to be produced
/asmversion:Version Version number of the assembly to be produced
/reference:FileName File name of assembly to use to resolve references
/publickey:FileName File containing strong name public key
/keyfile:FileName File containing strong name key pair
/keycontainer:FileName Key container holding strong name key pair
/delaysign Force strong name delay signing
/unsafe Produce interfaces without runtime security checks
/nologo Prevents TlbImp from displaying logo
/silent Suppresses all output except for errors
/verbose Displays extra information
/primary Produce a primary interop assembly
/sysarray Import SAFEARRAY as System.Array
/transform:TransformName Perform the specified transformation
/strictref Only use assemblies specified using /reference
/? or /help Display this usage message

The assembly version must be specified as: Major.Minor.Build.Revision.

Multiple reference assemblies can be specified by using the /reference option
multiple times.

Supported transforms:
DispRet Apply the [out, retval] parameter transformation
to methods of disp only interfaces

A resource ID can optionally be appended to the TypeLibName when importing a
type library from a module containing multiple type libraries.

For example: TlbImp MyModule.dll\1
nga96 2004-12-03
  • 打赏
  • 举报
回复
dll
kangxidadi 2004-12-03
  • 打赏
  • 举报
回复
lib转dll?
建一个dll项目,包含lib的头文件,setting里的link input加上你要的lib,或者在代码里加
#progma comment(lib,"xx.lib"), 用def定义你要的输出函数。连接生成dll文件。

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧