I am trying to use a C function from an unmanaged DLL in C#.
The signature of the function is:
const char* CDECL get_lame_version ( void );
I import the function this way:
[DllImport("libmp3lame.dll")]
static extern string get_lame_version();
If I call this function, but I break just before the call, then press F5, an AccessViolationException is thrown.
First the execution breaks just before the call:
then I press F5 and there is the exception:
If the execution breaks after the call instead, then there is no exception thrown:
So my question is: is there anything wrong with my code? If not, what is going on?
Edit
Here is the definition of 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;
}