日期:2014-05-19  浏览次数:20990 次

DLL只能调用一次
用vc编写的MFC   Dll程序在C#中调用   dll提供的是DCOM的接口函数
调用如下:
namespace   AClasstest
{
using   System.Runtime.InteropServices;
using   System.ComponentModel;
        class   CDll
        {
                [DllImport( "DcomDll.dll ",   EntryPoint   =   "test ",   SetLastError   =   true)]
                public   static   extern   int   test();
        }
        public   partial   class   Form1   :   Form
        {
                public   Form1()
                {
                        InitializeComponent();
                }

                private   void   button1_Click(object   sender,   EventArgs   e)
                {
                        int   c   =   0;
                        c   =   CDll.test();
                        if   (c   ==   1)
                                MessageBox.Show( "1 ");
                        else
                                MessageBox.Show( "0 ");
                }
        }
}
在VS中编译后运行的时候不能够正确连接DCOM的服务,但是在生成好后的文件下运行的时候能够正确运行一次,然后后面就不成功。但在vc的应用程序的情况下是能够正常运行的。
希望做过这方面的朋友帮忙解决下!

------解决方案--------------------
有些类库需要在DLL端执行释放的——否则不被回收,自然只能调用一次