本文介绍了如何创建在Web应用程序中使用的窗口应用程序DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的WindowsClassLibrary代码:



 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Windows.Forms;
使用 System.Net;
使用 System.IO;
使用 System.Drawing.Drawing2D;
使用 System.Drawing.Design;
使用 System.Threading;
使用 System.Drawing.Imaging;
使用 System.Configuration;
使用 System.Xml;
使用 InfoSoftGlobal;

命名空间 GraphCapture
{
public partial class Form1:UserControl
{
public Form1()
{
InitializeComponent();
}
public string filePath;
受保护 void SwfToImage()
{


屏幕= Screen.PrimaryScreen;


Rectangle bounds = new Rectangle(axShockwaveFlash1.Location,axShockwaveFlash1.Size);
使用(位图位图= 位图(bounds.Width,bounds.Height))
{
使用(图形g = Graphics.FromImage(位图))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic ;
g.CopyFromScreen( new Point(bounds.Left,bounds.Top),Point.Empty,bounds.Size);
}

bitmap.Save(filePath + / FCF_Column3D.Jpeg,ImageFormat.Jpeg);
}

}

public void GetGraph(XmlDocument strXml, string fPath)
{
string appPath = file:/// + Application.StartupPath + \\FusionCharts\\FCF_Column3D.swf;
appPath = appPath.Replace( \\ /);
filePath = fPath;
FileStream fs = new FileStream(filePath + \\ FCF_Column3D.Xml,FileMode.Open,FileAccess.Read);
strXml.Load(fs);
// string strChart = filePath + @?dataXML =+ strXml.InnerXml.Replace(\\ \\,')+®isterwithjs= 1;
// string ChartXML = appPath + strChart;
string ChartXML = appPath + @ ?dataXML = + strXml.InnerXml.Replace( \ ')。替换( )+ @isterwithjs = 1;



string XML = ChartXML;

axShockwaveFlash1.Movie = XML;
timer1.Start();


}

private void Form1_Load( object sender,EventArgs e)
{


}


private void timer1_Tick( object sender,EventArgs e)
{
SwfToImage();
timer1.Stop();

}
}
}





这里我收到错误 d27cdb6e-ae6d-11cf-96b8-444553540000'无法实例化,因为从Web应用程序调用dll时,当前线程不在单线程单元中

解决方案


Here is my code for WindowsClassLibrary:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Threading;
using System.Drawing.Imaging;
using System.Configuration;
using System.Xml;
using InfoSoftGlobal;

namespace GraphCapture
{
    public partial class Form1 : UserControl
    {
        public Form1()
        {
            InitializeComponent();
        }
        public string filePath ;
        protected void SwfToImage()
        {


            Screen screen = Screen.PrimaryScreen;


            Rectangle bounds = new Rectangle(axShockwaveFlash1.Location, axShockwaveFlash1.Size);
            using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
            {
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
                }

                bitmap.Save(filePath + "/FCF_Column3D.Jpeg", ImageFormat.Jpeg);
            }

        }

        public void GetGraph(XmlDocument strXml,string fPath)
        {
            string appPath = "file:///" + Application.StartupPath + "\\FusionCharts\\FCF_Column3D.swf";
            appPath = appPath.Replace("\\", "/");
            filePath = fPath;
            FileStream fs = new FileStream(filePath + "\\FCF_Column3D.Xml", FileMode.Open, FileAccess.Read);
            strXml.Load(fs);
            //string strChart = filePath + @"?dataXML=" + strXml.InnerXml.Replace("\"","'")  + "®isterwithjs=1";
            //string ChartXML = appPath + strChart;
            string ChartXML = appPath + @"?dataXML=" + strXml.InnerXml.Replace("\"", "'").Replace("#", "") + "®isterwithjs=1";



            string XML = ChartXML;

            axShockwaveFlash1.Movie = XML;
            timer1.Start();


        }

        private void Form1_Load(object sender, EventArgs e)
        {


        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            SwfToImage();
            timer1.Stop();

        }
    }
}



Here I am getting error d27cdb6e-ae6d-11cf-96b8-444553540000' cannot be instantiated because the current thread is not in a single-threaded apartment
while calling dll from web application.

解决方案



这篇关于如何创建在Web应用程序中使用的窗口应用程序DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 23:44