【发布时间】:2012-04-25 09:55:18
【问题描述】:
我正在尝试在 C# 中使用非托管 DLL 中的 C 函数。
函数的签名是:
const char* CDECL get_lame_version ( void );
我是这样导入函数的:
[DllImport("libmp3lame.dll")]
static extern string get_lame_version();
如果我调用了这个函数,但我在调用之前中断了,然后按 F5,就会抛出 AccessViolationException。
首先执行中断只是在调用之前:
然后我按 F5 出现异常:
如果执行中断调用,则不会抛出异常:
所以我的问题是:我的代码有什么问题吗?如果不是,那是怎么回事?
编辑
这里是get_lame_version的定义:
/*! Get the LAME version string. */
/*!
\param void
\return a pointer to a string which describes the version of LAME.
*/
const char *
get_lame_version(void)
{ /* primary to write screen reports */
/* Here we can also add informations about compile time configurations */
#if LAME_ALPHA_VERSION
static /*@observer@ */ const char *const str =
STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " "
"(alpha " STR(LAME_PATCH_VERSION) ", " __DATE__ " " __TIME__ ")";
#elif LAME_BETA_VERSION
static /*@observer@ */ const char *const str =
STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " "
"(beta " STR(LAME_PATCH_VERSION) ", " __DATE__ ")";
#elif LAME_RELEASE_VERSION && (LAME_PATCH_VERSION > 0)
static /*@observer@ */ const char *const str =
STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) "." STR(LAME_PATCH_VERSION);
#else
static /*@observer@ */ const char *const str =
STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION);
#endif
return str;
}
【问题讨论】:
标签: c# .net visual-studio-2010 debugging pinvoke