接口转换问题,懂C/C++的高手请进
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
问题点数:100、回复次数:16Top
1 楼Robinsonzhan(自己是一切的根源)回复于 2004-12-03 09:58:41 得分 0
本人e-mail:Robinsonzhan@126.com
改好了,给我发邮件,一定给分。先谢了。Top
2 楼Robinsonzhan(自己是一切的根源)回复于 2004-12-03 10:00:18 得分 0
或者MSN:zhanfalong@hotmail.com
谢谢!Top
3 楼xiaoslong(龙哥)回复于 2004-12-03 10:01:21 得分 10
帮你顶一下Top
4 楼Robinsonzhan(自己是一切的根源)回复于 2004-12-03 10:18:38 得分 0
多谢!Top
5 楼kangxidadi(康熙大帝)回复于 2004-12-03 10:30:24 得分 10
在.net别想直接使用.lib,你还是连接成.dll之后用importdll调用吧。Top
6 楼Robinsonzhan(自己是一切的根源)回复于 2004-12-03 10:36:36 得分 0
是啊,只有VC++可以,就是问怎么转换啊Top
7 楼kangxidadi(康熙大帝)回复于 2004-12-03 17:03:51 得分 10
lib转dll?
建一个dll项目,包含lib的头文件,setting里的link input加上你要的lib,或者在代码里加
#progma comment(lib,"xx.lib"), 用def定义你要的输出函数。连接生成dll文件。Top
8 楼nga96(因为我笨,所以努力。陈勇华)回复于 2004-12-03 18:29:02 得分 10
dllTop
9 楼x0000()回复于 2004-12-03 21:12:02 得分 30
使用类型库导出工具,生成一个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
Top
10 楼xiaoslong(龙哥)回复于 2004-12-03 22:10:39 得分 0
帮你顶Top
11 楼Robinsonzhan(自己是一切的根源)回复于 2004-12-04 20:20:33 得分 0
怎么写啊?Top
12 楼Robinsonzhan(自己是一切的根源)回复于 2004-12-13 09:04:27 得分 0
自己顶!Top
13 楼x0000()回复于 2004-12-13 09:07:33 得分 0
晕,查看命令的帮助Top
14 楼MyNameEPC(MyName)回复于 2004-12-13 09:57:51 得分 10
把文件编译成一个 DLL,这样就可以使用了,就像调用 Windows API 一样,使用 System.Runtime.InteropServices 就可以了,MSDN 和网上有很多关于 Interop 的。另外,如果不是 COM 的话,没有必要封装成 COM 再使用。Top
15 楼Robinsonzhan(自己是一切的根源)回复于 2005-01-05 14:43:45 得分 0
顶Top
16 楼cppTrier(修炼ing~~~)回复于 2005-01-05 14:52:27 得分 20
先编译成DLL(不需要是COM组件),然后用P/Invoke调用就可以了。Top




