我正在使用 DLLImport 从 C# 应用程序调用 GhostScript 库。
所以我有这样的代码,
[DllImport("gsdll32.dll", EntryPoint = "gsapi_init_with_args")]
private static extern int gsapi_init_with_args(IntPtr instance, int argc, IntPtr argv);
try
{
intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount, intptrArgs);
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message, ex);
}
我打算查看用 C 或 C++ 编写的 GhostScript 源代码,但总的来说,我想知道如果 GhostScript 代码抛出未处理的异常会发生什么?那会不会被那里的渔获物捕获,或者它必须看起来像这样,
catch
{
// blah
}
最佳答案
它不会抛出异常,您应该查看返回码。 http://pages.cs.wisc.edu/~ghost/doc/AFPL/7.04/API.htm#return_codes
C 编程的非常标准的方法,错误返回非零代码,有时会在第二个 API 调用后检索错误的更多详细信息。
关于c# - 使用 DLLImport 时异常如何工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10201848/