关于DllImport的建议

关于DllImport的建议

本文介绍了关于DllImport的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我正在开发一个需要动态创建目录的C#应用​​程序。 强制执行的安全设置我们的ISP不允许我们使用 标准的.NET调用,所以我不得不求助于COM的一个DllImport 库''msvcrt.dll'' 。但是我不熟悉调用COM 对象所以我有问题... 1)如何销毁你创建的每个COM对象规则适用于这里? 代码如下我创建的东西需要 销毁? 2)如果这个函数经常调用什么是性能 后果? [DllImport(" msvcrt.dll",SetLastError = true)] static extern int _mkdir(string path); ///< summary> ///这个函数应该为 $提供安全的替代b $ b Directory.CreateDirectory() ///< / summary> ///< param name =" path">< / param> ; ///< returns>< / returns> 静态DirectoryInfo CreateDirectory(字符串sPath) { int iCode = _mkdir(sPath); if(iCode!= 0) { 抛出新的ApplicationException (错误调用[msvcrt.dll]:_ mkdir(" + sPath +"),错误代码:" + iCode.ToString()); } 返回新的DirectoryInfo(sPath); } thx一百万 解决方案 msvcrt.dll不是COM DLL而是Win32 DLL。 我觉得很难相信你的ISP没有 允许Directory.CreateDirectory但允许使用 的msvcrt.dll - 它没有任何意义。 Arne 你没有在这里创建一个COM对象,所以没有什么可以销毁。 无。但正如其他人所说的那样,我会想象这也不会起作用。 Michael hi guys,I am working on a C# app that needs to create directories on the fly.security settings enforced by our ISP do not allow us to use thestandard .NET calls, so I am forced to resort to a DllImport of the COMlibrary ''msvcrt.dll''. however I am not familiar with calling COMobjects so I have questions...1) how does the "destroy every COM object you create" rule apply here?with the code below am I creating something that needs to bedestroyed?2) if this function is called often what are the performanceconsequences?[DllImport("msvcrt.dll", SetLastError=true)]static extern int _mkdir(string path);/// <summary>/// This function should provide safe substitude forDirectory.CreateDirectory()/// </summary>/// <param name="path"></param>/// <returns></returns>static DirectoryInfo CreateDirectory(string sPath){int iCode = _mkdir(sPath);if (iCode != 0){throw new ApplicationException("Error calling [msvcrt.dll]:_mkdir(" +sPath + "), error code: " + iCode.ToString());}return new DirectoryInfo(sPath);}thx a million 解决方案msvcrt.dll is not a COM DLL but a Win32 DLL.I find it hard to believe that your ISP does notallow Directory.CreateDirectory but allow usageof msvcrt.dll - it does not make any sense.ArneYou are not creating a COM object here so there is nothing to destroy.None. But as other''s have said I''d imagine this aint gunna work either.Michael 这篇关于关于DllImport的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 00:31