从vb6 dll绘制.Net设备上下文 [英] Drawing on a .Net device context from a vb6 dll

查看:70
本文介绍了从vb6 dll绘制.Net设备上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个vb6应用程序。在主窗体上是一张图片

框,里面有一两张图片和几张文字

。这些是使用gdi32

例程在运行中创建的,这些例程都在引用的自定义dll中。我在dll中调用了

的PrintImage例程,并仅从主窗体传递了

Picturebox.hdc。 dll的打印程序

吸引到hdc,它显示在图片框中

完美。


我会喜欢用asp.net页面做类似的事情

使用我同样的vb6自定义打印dll。其中Display.aspx

有和IMG标签src =" Image.aspx" ;.现在,在

Image.aspx.vb代码中,我对我的dll

进行必要的调用以预加载一些数据,然后调用PrintImage例程。

我得到的是一个黑盒子。因为它是一个asp.net页面

我没有一个可以绘制的图片框(即使我做了,我是

不确定picturebox'的句柄与

vb6'的hdc相同。所以我正在尝试在.net中创建一个位图

我最终可以得到一个hdc,我可以发送到我在vb6 dll中的打印

例程。下面是我用来做这个的代码:


Dim bm As Bitmap = New Bitmap(728,312)

Dim gfx As Graphics = Graphics.FromImage (bm)

gfx.Clear(Color.White)

Dim hDC As IntPtr = gfx.GetHdc()

prt.hdc = hDC .ToInt32''prt.hdc是我的vb6

dll中的属性,它接收要打印的hdc


代码运行没有错误,我保存位图到一个文件,

把它读成一个bytearray,并做一个

Response.Binarywrite ...我得到一个黑盒子(好吧,现在我得到了

a白盒子,因为我在上面添加了gfx.Clear线。)


为什么我的vb6打印dll不能绘制到.net hdc?


PS。我最终不想将位图保存到

一个文件。如果我可以在设备上获得正确的图形

上下文,我希望能够将它直接传输到

字节数组并执行Response.Binarywrite 。


如果专家可以帮助解决我的主要问题和我的PS。我很高兴。
$ div class =h2_lin>解决方案




你可以尝试在VB6 dll完成绘制后调用ReleaseDC。

其余的.NET代码看起来是正确的。您可能还想调试VB6 dll

以查看它可能失败的位置。


-

Dmitriy Lapshin [C# / .NET MVP]

X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx

将单元测试的强大功能带到VS .NET IDE


" Metallicraft" <一个******* @ discussions.microsoft.com>在消息中写道

news:06 **************************** @ phx.gbl ... < blockquote class =post_quotes>我有一个vb6应用程序。在主窗体上是一个图片
框,其中显示一个或两个图像和几个文本。这些是使用gdi32
例程动态创建的,这些例程都在引用的自定义dll中。我在dll中调用了一个PrintImage例程,并仅从主窗体传递了Picturebox.hdc。 dll的打印程序
吸引到hdc,它完全显示在图片框中。

我想用asp.net页面做类似的事情
使用我同样的vb6自定义打印dll。 Display.aspx
有的地方和带有src =" Image.aspx的IMG标签。现在,在
Image.aspx.vb代码中,我对我的dll进行必要的调用
来预加载一些数据,然后我调用PrintImage例程。
我得到的是黑色框。因为它是一个asp.net页面
我没有一个可以绘制的图片框(即使我这样做,我也不确定图片框的句柄是否是和
vb6'的hdc相同)。所以我正在尝试在.net中创建一个位图,我最终可以得到一个hdc,我可以发送到我在vb6 dll中的打印例程。下面是我用来做这个的代码:

Dim bm As Bitmap = New Bitmap(728,312)
Dim gfx As Graphics = Graphics.FromImage(bm)
gfx .Clear(Color.White)
Dim hDC As IntPtr = gfx.GetHdc()
prt.hdc = hDC.ToInt32''prt.hdc是我的vb6
dll中的属性将hdc打印到

代码运行没有错误,我将位图保存到一个文件,
将其读入一个bytearray,并做一个
Response.Binarywrite ...我得到一个黑盒子(好吧,现在我得到了一个白盒子,因为我在上面添加了gfx.Clear线)。

为什么我的vb6打印dll不能画到。净hdc?

PS。我最终不想将位图保存到文件中。如果我可以在设备上下文中获得正确的图形,我希望能够将其直接传输到
字节数组并执行Response.Binarywrite。
如果专家可以帮助解决我的主要问题和我的PS。我非常感谢。




感谢您的回复。


我我将位图写入

将位图发送到代码中的文件中后,处理我的位图并释放直流。我知道

vb6 dll在vb6中有效。 vb6 dll是生产软件

已经在数百个客户手中工作。


我可以做一个:


gfx.DrawString(" test",New Font(" Arial",24.0F),

Brushes.Black,0,0)

gfx。 DrawRectangle(New Pen(Color.Black),New

Rectangle(2,1,725,309))


....在vb.net内并获得一个带有文本和

矩形的位图,但是当传递图形的'hdc

(Graphic.GetHdc.ToInt32)时,我得不到任何来自

vb6 dll。

-----原始消息-----
你好,

你可以尝试在VB6 dll完成绘图后调用ReleaseDC。 .NET代码看起来是正确的。您可能还想要
调试VB6,看看它可能会失败的地方。

- Dmitriy Lapshin [C#/ .NET MVP]
X-Unity测试工作室
http://x-unity.miik.com .ua / teststudio.aspx
将单元测试的强大功能带到VS .NET IDE

Metallicraft。 <一个******* @ discussions.microsoft.com>
在messagenews中写道:06 **************************** @ phx.gbl ...

我有一个vb6应用程序。在主窗体上是一个图片
框,其中显示一个或两个图像和几个文本。这些是使用
gdi32例程在运行中创建的,这些例程都在引用的自定义dll中。我
在dll中调用PrintImage例程,并仅从主窗体传递
Picturebox.hdc。 dll'的打印
例程吸引到hdc,它完全显示在图片框中。

我想用asp.net页面做类似的事情
使用我同样的vb6自定义打印dll。其中
Display.aspx有和IMG标签src =" Image.aspx" ;.现在,在
Image.aspx.vb代码中,我对我的dll进行必要的调用
来预加载一些数据,然后我调用PrintImage
例程。我得到的是一个黑盒子。由于它是一个asp.net
页面,我没有一个可以绘制的图片框(即使我这样做,我也不确定图片框的句柄是否是和
vb6'的hdc相同)。所以我正在尝试在.net
中创建一个位图,我最终可以获得一个hdc,我可以将其发送到vb6 dll中的
打印例程。下面是我用来做
的代码:
Dim bm As Bitmap = New Bitmap(728,312)
Dim gfx As Graphics = Graphics.FromImage(bm)
gfx .Clear(Color.White)
Dim hDC As IntPtr = gfx.GetHdc()
prt.hdc = hDC.ToInt32''prt.hdc是我的vb6
dll中的属性hdc打印到

代码运行没有错误,我将位图保存到
文件,将其读入一个bytearray,并做一个
Response.Binarywrite ...我得到一个黑盒子(好吧,现在我因为我在上面添加了gfx.Clear线而获得了一个白盒子。)

为什么我的vb6打印dll不能画到。净hdc?

PS。我最终不想将位图
保存到文件中。如果我可以在设备上下文中获得正确的图形,我希望能够将其直接传输到
a字节数组并执行Response.Binarywrite。

如果专家可以帮助解决我的主要问题和我的PS。我非常感谢。





您可以尝试调用原始GDI函数通过HDC上的P / Invoke获得

并查看它是否有效。如果是的话,你至少知道传递的HDC是否有效。


在单独的线程上运行的VB6 COM DLL也可能存在问题/>
(因为它在单线程公寓中运行,ASP .NET是多线程的
),我不确定HDC是否可以按原样传递。

线程之间。


-

Dmitriy Lapshin [C#/ .NET MVP]

X-Unity测试工作室
http:// x-unity .miik.com.ua / teststudio.aspx

将单元测试的强大功能带到VS .NET IDE


" Metallicraft" <一个******* @ discussions.microsoft.com>在消息中写道

news:08 **************************** @ phx.gbl ... < blockquote class =post_quotes>感谢您的回复。

在我将位图写入代码中的文件后,我处理了我的位图并释放了直流。我知道
vb6 dll在vb6中有效。 vb6 dll是已经在数百个客户手中工作的生产软件。

我可以做一个:

gfx.DrawString(" test",新字体(Arial,24.0F),
Brushes.Black,0,0)
gfx.DrawRectangle(New Pen(Color.Black),New
Rectangle(2,1) ,725,309))

...在vb.net内部获取带有文本和
矩形的位图,但是当传递图形的'hdc
时(图形.GetHdc.ToInt32)我没有从vb6 dll得到任何图纸。

-----原始信息-----
你好,

您可以尝试在VB6 dll完成绘图后调用ReleaseDC。


完成绘图。

.NET代码的其余部分看起来是正确的。你可能还想


调试你的VB6 dll

来看看它可能失败的地方。

-
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
将单元测试的强大功能带到VS .NET IDE

Metallicraft。 < an ******* @ discussion.microsoft.com>


在消息中写道

新闻:06 *********** ***************** @phx.gbl ...

我有一个vb6应用程序。在主窗体上是一个图片
框,其中显示一个或两个图像和几个文本。这些是使用gdi32例程在运行中创建的,这些例程都在引用的自定义dll中。我在dll中调用了一个PrintImage例程,并仅从主窗体传递了Picturebox.hdc。 dll的打印程序吸引到hdc,它完全显示在图片框中。

我想用asp.net页面做类似的事情
使用我相同的vb6自定义打印dll。 Display.aspx有的地方和带有src =" Image.aspx的IMG标签。现在,在
Image.aspx.vb代码中,我对我的dll进行必要的调用
来预加载一些数据,然后我调用PrintImage例程。我得到的是一个黑盒子。因为它是一个asp.net页面,所以我没有一个可以绘制的图片框(即使我这样做了,我也不确定图片框的句柄是否与
vb6'的hdc)。所以我正在尝试在.net中创建一个位图,我最终可以获得一个hdc,我可以将其发送到vb6 dll中的打印例程。下面是我用来做这个的代码:
Dim bm As Bitmap = New Bitmap(728,312)
Dim gfx As Graphics = Graphics.FromImage(bm)
gfx.Clear(Color .White)
Dim hDC As IntPtr = gfx.GetHdc()
prt.hdc = hDC.ToInt32''prt.hdc是我的vb6
dll中的属性,它接收要打印的hdc代码运行没有错误,我将位图保存到一个文件,将其读入一个bytearray,并做一个
Response.Binarywrite ...我得到一个黑盒子(好吧,现在我得到了一个白盒子,因为我在上面添加了gfx.Clear线。)

为什么我的vb6打印dll不能绘制到.net hdc?

PS 。我最终不想将位图保存到文件中。如果我能在设备上下文中获得正确的图形,我希望能够将其直接传输到字节数组并执行Response.Binarywrite。

如果是专家可以帮助我的主要问题和我的PS。我非常感谢。






I have a vb6 application. On the main form is a picture
box with one or two images and several pieces of text
displayed in it. These are created on the fly using gdi32
routines that are all in a referenced, custom dll. I call
a PrintImage routine in the dll and pass it only the the
Picturebox.hdc from the main form. The dll''s print routine
draws to the hdc and it shows up in the picturebox
perfectly.

I would like to do a similar thing with an asp.net page
using my same vb6 custom printing dll. Where Display.aspx
has and IMG tag with src="Image.aspx". Now, in the
Image.aspx.vb code, I make the necessary calls to my dll
to preload some data, then I call the PrintImage routine.
What I get back is a black box. Since it''s an asp.net page
I don''t have a picturebox to draw to (even if I did, I''m
not sure the picturebox''s Handle would be the same as
vb6''s hdc). So I''m trying to create a bitmap in .net where
i can eventually get an hdc that I can send to my printing
routine in the vb6 dll. Below is the code I use to do this:

Dim bm As Bitmap = New Bitmap(728, 312)
Dim gfx As Graphics = Graphics.FromImage(bm)
gfx.Clear(Color.White)
Dim hDC As IntPtr = gfx.GetHdc()
prt.hdc = hDC.ToInt32 ''prt.hdc is the property in my vb6
dll that receives the hdc to print to

The code runs without error, I save the bitmap to a file,
read it into a bytearray, and do a
Response.Binarywrite...I get a black box (well, now I get
a white box since I added the gfx.Clear line above).

Why can''t my vb6 printing dll draw to a .net hdc?

PS. I eventually don''t want to have to save the bitmap to
a file. If I can get the correct drawing on a device
context, I''d like to be able to stream that directly to a
byte array and do a Response.Binarywrite.

If an expert can help with my main issue and my PS. I
would greatly appreciate it.

解决方案

Hi,

You can try calling ReleaseDC after the VB6 dll has finished drawing. The
rest of .NET code looks correct. You might also want to debug your VB6 dll
to see where it possibly fails.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Metallicraft" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...

I have a vb6 application. On the main form is a picture
box with one or two images and several pieces of text
displayed in it. These are created on the fly using gdi32
routines that are all in a referenced, custom dll. I call
a PrintImage routine in the dll and pass it only the the
Picturebox.hdc from the main form. The dll''s print routine
draws to the hdc and it shows up in the picturebox
perfectly.

I would like to do a similar thing with an asp.net page
using my same vb6 custom printing dll. Where Display.aspx
has and IMG tag with src="Image.aspx". Now, in the
Image.aspx.vb code, I make the necessary calls to my dll
to preload some data, then I call the PrintImage routine.
What I get back is a black box. Since it''s an asp.net page
I don''t have a picturebox to draw to (even if I did, I''m
not sure the picturebox''s Handle would be the same as
vb6''s hdc). So I''m trying to create a bitmap in .net where
i can eventually get an hdc that I can send to my printing
routine in the vb6 dll. Below is the code I use to do this:

Dim bm As Bitmap = New Bitmap(728, 312)
Dim gfx As Graphics = Graphics.FromImage(bm)
gfx.Clear(Color.White)
Dim hDC As IntPtr = gfx.GetHdc()
prt.hdc = hDC.ToInt32 ''prt.hdc is the property in my vb6
dll that receives the hdc to print to

The code runs without error, I save the bitmap to a file,
read it into a bytearray, and do a
Response.Binarywrite...I get a black box (well, now I get
a white box since I added the gfx.Clear line above).

Why can''t my vb6 printing dll draw to a .net hdc?

PS. I eventually don''t want to have to save the bitmap to
a file. If I can get the correct drawing on a device
context, I''d like to be able to stream that directly to a
byte array and do a Response.Binarywrite.

If an expert can help with my main issue and my PS. I
would greatly appreciate it.




Thanks for responding.

I dispose of my bitmap and release the dc after I write
the bitmap to a file further down in the code. I know the
vb6 dll works in vb6. The vb6 dll is production software
already working in the hands of hundreds of clients.

I can do a:

gfx.DrawString("test", New Font("Arial", 24.0F),
Brushes.Black, 0, 0)
gfx.DrawRectangle(New Pen(Color.Black), New
Rectangle(2, 1, 725, 309))

....inside vb.net and get a bitmap with text and a
rectangle, but when passing the graphic''s hdc
(Graphic.GetHdc.ToInt32) I get no drawing whatsoever from
the vb6 dll.

-----Original Message-----
Hi,

You can try calling ReleaseDC after the VB6 dll has finished drawing. Therest of .NET code looks correct. You might also want to debug your VB6 dllto see where it possibly fails.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Metallicraft" <an*******@discussions.microsoft.com> wrote in messagenews:06****************************@phx.gbl...

I have a vb6 application. On the main form is a picture
box with one or two images and several pieces of text
displayed in it. These are created on the fly using gdi32 routines that are all in a referenced, custom dll. I call a PrintImage routine in the dll and pass it only the the
Picturebox.hdc from the main form. The dll''s print routine draws to the hdc and it shows up in the picturebox
perfectly.

I would like to do a similar thing with an asp.net page
using my same vb6 custom printing dll. Where Display.aspx has and IMG tag with src="Image.aspx". Now, in the
Image.aspx.vb code, I make the necessary calls to my dll
to preload some data, then I call the PrintImage routine. What I get back is a black box. Since it''s an asp.net page I don''t have a picturebox to draw to (even if I did, I''m
not sure the picturebox''s Handle would be the same as
vb6''s hdc). So I''m trying to create a bitmap in .net where i can eventually get an hdc that I can send to my printing routine in the vb6 dll. Below is the code I use to do this:
Dim bm As Bitmap = New Bitmap(728, 312)
Dim gfx As Graphics = Graphics.FromImage(bm)
gfx.Clear(Color.White)
Dim hDC As IntPtr = gfx.GetHdc()
prt.hdc = hDC.ToInt32 ''prt.hdc is the property in my vb6
dll that receives the hdc to print to

The code runs without error, I save the bitmap to a file, read it into a bytearray, and do a
Response.Binarywrite...I get a black box (well, now I get a white box since I added the gfx.Clear line above).

Why can''t my vb6 printing dll draw to a .net hdc?

PS. I eventually don''t want to have to save the bitmap to a file. If I can get the correct drawing on a device
context, I''d like to be able to stream that directly to a byte array and do a Response.Binarywrite.

If an expert can help with my main issue and my PS. I
would greatly appreciate it.



.



You can try calling a raw GDI function through P/Invoke on the HDC obtained
and see whether it works that way. If yes, you at least know the HDC being
passed is valid.

There also could be problems with VB6 COM DLL running on a separate thread
(as it runs in the Single-Threaded Apartment and ASP .NET is
multi-threaded), and I am not sure HDCs can be passed "as is" between
threads.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Metallicraft" <an*******@discussions.microsoft.com> wrote in message
news:08****************************@phx.gbl...

Thanks for responding.

I dispose of my bitmap and release the dc after I write
the bitmap to a file further down in the code. I know the
vb6 dll works in vb6. The vb6 dll is production software
already working in the hands of hundreds of clients.

I can do a:

gfx.DrawString("test", New Font("Arial", 24.0F),
Brushes.Black, 0, 0)
gfx.DrawRectangle(New Pen(Color.Black), New
Rectangle(2, 1, 725, 309))

...inside vb.net and get a bitmap with text and a
rectangle, but when passing the graphic''s hdc
(Graphic.GetHdc.ToInt32) I get no drawing whatsoever from
the vb6 dll.

-----Original Message-----
Hi,

You can try calling ReleaseDC after the VB6 dll has


finished drawing. The

rest of .NET code looks correct. You might also want to


debug your VB6 dll

to see where it possibly fails.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Metallicraft" <an*******@discussions.microsoft.com>


wrote in message

news:06****************************@phx.gbl...

I have a vb6 application. On the main form is a picture
box with one or two images and several pieces of text
displayed in it. These are created on the fly using gdi32 routines that are all in a referenced, custom dll. I call a PrintImage routine in the dll and pass it only the the
Picturebox.hdc from the main form. The dll''s print routine draws to the hdc and it shows up in the picturebox
perfectly.

I would like to do a similar thing with an asp.net page
using my same vb6 custom printing dll. Where Display.aspx has and IMG tag with src="Image.aspx". Now, in the
Image.aspx.vb code, I make the necessary calls to my dll
to preload some data, then I call the PrintImage routine. What I get back is a black box. Since it''s an asp.net page I don''t have a picturebox to draw to (even if I did, I''m
not sure the picturebox''s Handle would be the same as
vb6''s hdc). So I''m trying to create a bitmap in .net where i can eventually get an hdc that I can send to my printing routine in the vb6 dll. Below is the code I use to do this:
Dim bm As Bitmap = New Bitmap(728, 312)
Dim gfx As Graphics = Graphics.FromImage(bm)
gfx.Clear(Color.White)
Dim hDC As IntPtr = gfx.GetHdc()
prt.hdc = hDC.ToInt32 ''prt.hdc is the property in my vb6
dll that receives the hdc to print to

The code runs without error, I save the bitmap to a file, read it into a bytearray, and do a
Response.Binarywrite...I get a black box (well, now I get a white box since I added the gfx.Clear line above).

Why can''t my vb6 printing dll draw to a .net hdc?

PS. I eventually don''t want to have to save the bitmap to a file. If I can get the correct drawing on a device
context, I''d like to be able to stream that directly to a byte array and do a Response.Binarywrite.

If an expert can help with my main issue and my PS. I
would greatly appreciate it.



.




这篇关于从vb6 dll绘制.Net设备上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆