简体   繁体   English

跨DLL边界使用Direct2D

[英]Using Direct2D across DLL boundaries

So I started writing a program in C that would require a lot of fancy drawing, but I'm strictly on Windows, so I decided to use Direct2D. 因此,我开始用C语言编写一个程序,该程序需要很多精美的图片,但是我严格地在Windows上,所以我决定使用Direct2D。

As of right now I create a custom control in a DLL, which the program consumes and uses like any other Win32 control. 截至目前,我在DLL中创建了一个自定义控件,该程序像其他Win32控件一样使用和使用该控件。 The custom control sets up a D2D context inside its window and draws into it for whatever it needs, and this works fine. 定制控件在其窗口内设置一个D2D上下文,并根据需要使用它,并且可以正常工作。

I realized this would make for a very useful DLL in future projects for setting up and tearing down Direct2D easily through a traditional control interface, so I made the control send a notification to the parent window when it was time to draw instead of calling its own internal drawing code (basically like owner-drawn controls). 我意识到这将为将来的项目中提供一个非常有用的DLL,以便通过传统的控件界面轻松设置和删除Direct2D,因此我使控件在需要绘制时将通知发送到父窗口,而不是调用它自己的窗口内部绘图代码(基本上像所有者绘制的控件一样)。 It calls BeginDraw, then sends the notification to the parent with a custom NMHDR that includes a pointer to the ID2D1DCRenderTarget, then calls EndDraw. 它调用BeginDraw,然后使用包含指向ID2D1DCRenderTarget的指针的自定义NMHDR将通知发送给父级,然后调用EndDraw。 In my main window, I create the control, then respond to the notification, then call methods to draw stuff, then return. 在主窗口中,我创建控件,然后响应通知,然后调用方法绘制内容,然后返回。

The problem is that when EndDraw is called in the DLL, I get the error "The object was not in the correct state to process the method". 问题是,在DLL中调用EndDraw时,出现错误“对象未处于正确状态以处理该方法”。 This makes me think that crossing DLL boundaries must muck with the operation. 这使我认为跨越DLL边界必须与操作混为一谈。 Do DLLs always run in the same thread as the attached process? DLL是否总是与附加进程在同一线程中运行? Is there some other oddity about crossing through DLL boundaries, especially with respect to Direct2D? 跨越DLL边界是否还有其他奇怪之处,尤其是在Direct2D方面?

Thanks. 谢谢。

This makes me think that crossing DLL boundaries must muck with the operation. 这使我认为跨越DLL边界必须与操作混为一谈。 Do DLLs always run in the same thread as the attached process? DLL是否总是与附加进程在同一线程中运行? Is there some other oddity about crossing through DLL boundaries, especially with respect to Direct2D? 跨越DLL边界是否还有其他奇怪之处,尤其是在Direct2D方面?

No, calling a function that lives in a different DLL is no different from calling a function in the same module as the caller. 不,调用驻留在不同DLL中的函数与调用方在同一模块中调用函数没有什么不同。 Remember that the standard Windows controls always exist in different modules from their hosts, eg user32.dll, comctl32.dll and so on. 请记住,标准Windows控件始终与其主机位于不同的模块中,例如user32.dll,comctl32.dll等。

The problem in your code is not related to it residing in a different module. 您的代码中的问题与驻留在其他模块中的问题无关。

Thanks for the responses! 感谢您的回复! Just realized that it had to do with the binding of the DC to the RenderTarget, so blame me. 刚刚意识到这与DC与RenderTarget的绑定有关,所以请怪我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM