几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » DirectDWG
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-05-07, 04:01 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】singledoc In .ne

singledoc in .net
singledoc in .net
hello
i must admit, i have already posted this question. for some reason i have gotten no response so far. chances are, my question was just not accurate enough. anyway, here i go again (hopefully a little clearer...):
i'd like to implement a viewer using .net windows forms. especially i'd like to know if it is possible to do that without mfc and in what time this task could be accomplished. i've studied the singledoc example and also found a post about the very same topic:
device->update access violation (c++ .net)
hello
i searched the forum once again and found this post:
i used the posted vs project from "davidenglish" and made it compile and run. it shows a simple windows form with an control in it. the handle to the control is passed to the device-properties (device is created by the wingdi module). the loaded dxf-drawing is not shown. when i call device->update() i get an access violation.
as recommended in other posts, i keep the smartpointers to the used od-objects.
can you please explain to me, why i am getting this access violation and how (if possible) i can avoid it?
this is the code (originally davidenglish's code):
code:
#pragma once
#pragma warning (disable:4482)
#include "odacommon.h"
#include <dbdatabase.h>
#include <dbfiler.h>
#include "dbdictionary.h"
#include "exsystemservices.h"
#include "exhostappservices.h"
#include "dbgsmanager.h"
#include "rxvariantvalue.h"
#include "gicontextfordbdatabase.h"
//#include "exgsscreendevice.h"
//#include "exgsgdivectorizedevice.h"
//#include "exgsbitmapdevice.h"
#include "rxdynamicmodule.h"
#include "abstractviewpe.h"
#include "keeper.h"
void odgsinitialize();
using namespace system;
using namespace system::componentmodel;
using namespace system::collections;
using namespace system::windows::forms;
using namespace system::data;
using namespace system::drawing;
namespace simplegdi {
keeper mykeeper;
public ref class acadwingdicontrol : windows::forms::control {
public:
acadwingdicontrol() {
this->backcolor = drawing::color::lightblue;
//windows::forms::messagebox::show(((odint32)this->handle.toint32()).tostring());
}

virtual void onhandlecreated(system::eventargs^ e) override {
control:nhandlecreated(e);
try{
mykeeper.hostappservices = odrxobjectimpl<exhostappservices>::createobject();
mykeeper.systemservices = odrxobjectimpl<exsystemservices>::createobject();
odinitialize(mykeeper.systemservices);
mykeeper.pgs = :drxdynamiclinker()->loadmodule(l"wingdi.gs");
odgsinitialize();
if (mykeeper.pgs.isnull()) {
throw gcnew exception("error loading module");
}
mykeeper.pdb = mykeeper.hostappservices->readfile(l"d:\\muster.dxf");
if (mykeeper.pdb.isnull()) {
throw gcnew exception("error opening database");
}
mykeeper.m_pdevice = mykeeper.pgs->createdevice();
if (mykeeper.m_pdevice.isnull()) {
throw gcnew exception("error creating gdi render device");
}
odrxdictionaryptr pproperties = mykeeper.m_pdevice->properties();
pproperties->putat(l"windowhwnd",odrxvariantvalue( (odint32)this->handle.toint32() ));

odgicontextfordbdatabaseptr pdwgcontext = odgicontextfordbdatabase::createobject();
pdwgcontext->setdatabase(mykeeper.pdb);
mykeeper.m_pdevice = oddbgsmanager::setupactivelayoutviews(mykeeper.m_pdevice,pdwgcontext);
odgsdcrect outputrect( odgsdcpoint(0, 0), odgsdcpoint(100, 100) );
mykeeper.m_pdevice->onsize(outputrect);
odgsview* pview = mykeeper.m_pdevice->viewat(0);
odabstractviewpeptr(pview)->zoomextents(pview);
}catch( oderror e ){
odstring err = e.description();
}
}
virtual void ondoubleclick( system::eventargs^ e ) override {
control:ndoubleclick(e);
if( !mykeeper.m_pdevice.isnull() ){
mykeeper.m_pdevice->update();
}
}
~acadwingdicontrol() {
}
};
}this is the class i keep the relevant objects in:
code:
#pragma once
namespace simplegdi {
public class keeper {
public:
odgsdeviceptr m_pdevice;
oddbdatabaseptr pdb;
odsmartptr<exsystemservices> systemservices;
odsmartptr<exhostappservices> hostappservices;
odgsmoduleptr pgs;
};
};the error message when m_pdevice->update() is called:
quote:
an unhandled exception of type 'system.accessviolationexception' occurred in simplegdi.exe
additional information: attempted to read or write protected memory. this is often an indication that other memory is corrupt.
the call stack:
code:
wingdi_2.06_9.gs!04878769()
[frames below may be incorrect and/or missing, no symbols loaded for wingdi_2.06_9.gs]
wingdi_2.06_9.gs!0488cb55()
wingdi_2.06_9.gs!0488cd10()
dd_gs_2.06_9.dll!0145c802()
dd_db_2.06_9.dll!0086e30e()
[external code]
> simplegdi.exe!simplegdi::acadwingdicontrol:ndoubleclick(system::eventargs^ e = 0x02485c20) line 90 c++
[external code]
user32.dll!77d48734()
user32.dll!77d48816()
user32.dll!77d489cd()
simplegdi.exe!main(array<system::string^> ^ args = {length=0}) line 16 c++
mscoree.dll!7900b1b3()
kernel32.dll!7c816d4f()can the device draw into a windows forms control? is this a matter of managed/unmanaged code or am i ignoring some important dwgdirect rules?
please don't let me hang here. any help is welcome. thanks
martin
you may try to build the project with debug dlls, and turn on unmanaged debugging - that will at least give us proper call stack.
vladimir
yes, i definitely may want to do that... i was using the release dlls, no excuse for that. as for turning on unmanaged debugging -> i switched from "auto" to "mixed", can't tell if that helped.
here is the call stack:
code:
> wingdi_2.06_9.gs!exgigdigeometry::beginpaint(hdc__ * htargetdc=0x0f010427) line 221 + 0xb bytes c++
wingdi_2.06_9.gs!exgsgdivectorizedevice::beginpaint() line 208 c++
wingdi_2.06_9.gs!exgsgdivectorizedevice::updatescreen() line 249 c++
dd_gs_2.06_9.dll!odgsbasevectorizedevice::update(odgsdcrect * prect=0x00000000) line 391 + 0x12 bytes c++
wingdi_2.06_9.gs!exgsgdivectorizedevice::update(odgsdcrect * pupdatedrect=0x00000000) line 269 c++
dd_db_2.06_9.dll!odgsmodellayouthelperimpl::update(odgsdcrect * pupdatedrect=0x00000000) line 718 + 0x21 bytes c++
[external code]
simplegdi.exe!simplegdi::acadwingdicontrol:npaint(system::windows::forms:ainteventargs^ e = 0x0247d3b8) line 122 + 0x29 bytes c++
[external code]
user32.dll!77d48734()
[frames below may be incorrect and/or missing, no symbols loaded for user32.dll]
user32.dll!77d48816()
user32.dll!77d4b4c0()
user32.dll!77d4b50c()
user32.dll!77d4b530()
simplegdi.exe!main(array<system::string^> ^ args = {length=0}) line 16 c++
mscoree.dll!7900b1b3()
kernel32.dll!7c816d4f()and here is a new version of my code. user "than" gave me parts of his solution he found 2 years ago. that was very nice of him, thanks again. to give you the context:
i define my own control, inherited from system::windows::forms::control and am overwriting its onpaint methode in order to get to the graphics-object which comes in the painteventargs. there i get the handle to the hdc and pass it on to the device. on device->update() i get the access violation.
code:
virtual void onpaint(system::windows::forms:ainteventargs^ e) override{
control:npaint(e);
try{
if( !mykeeper.m_pdevice.isnull() ){
// "g" is an instance of system::drawing::graphics
intptr hdc = e->graphics->gethdc();
odint32 handlevalue = (odint32)hdc.toint32();
odrxdictionaryptr pproperties = mykeeper.m_pdevice->properties();
if (pproperties->has(dd_t("windowhdc"))){
pproperties->putat(dd_t("windowhdc"), odrxvariantvalue(handlevalue));
}
if (pproperties->has(dd_t("doublebufferenabled"))){
pproperties->putat(dd_t("doublebufferenabled"), odrxvariantvalue(false));
}
if (pproperties->has(dd_t("clearscreen"))){
pproperties->putat(dd_t("clearscreen"), odrxvariantvalue(false));
}
if (pproperties->has(dd_t("enablesoftwarehlr"))){
pproperties->putat(dd_t("enablesoftwarehlr"), odrxvariantvalue(false));
}
if (pproperties->has(dd_t("discardbackfaces"))){
pproperties->putat(dd_t("discardbackfaces"), odrxvariantvalue(false));
}
mykeeper.m_pdevice = oddbgsmanager::setupactivelayoutviews(mykeeper.m_pdevice, mykeeper.pcontext);
// code to render the drawing
if (! mykeeper.pdb.isnull() && ! mykeeper.m_pdevice.isnull())
{
odgsdcrect gsrect(0, 256, 256, 0); // you'll have to provide the dimensions of the output device
mykeeper.m_pdevice->onsize(gsrect);
mykeeper.m_pdevice->ondisplaychange(16, 256, 256); // same as above
odgsviewptr pview = mykeeper.m_pdevice->viewat(0);
pview->setviewportborderproperties(odrgb(0x00, 0x00, 0x00), 0);
pview->setviewportbordervisibility(false);
pview->setviewport(gsrect);
odabstractviewpeptr(pview)->zoomextents(pview);
pview->setview(pview->position(), pview->target(), pview->upvector() , pview->fieldwidth(), pview->fieldheight(), odgsview::kparallel);
mykeeper.m_pdevice->invalidate();
//if( mykeeper.m_pdevice->isvalid() ){
mykeeper.m_pdevice->update();
//}
}
}
}catch( oderror e ){
odstring err = e.description();
}
}what am i doing wrong? thanks vladimir, i'm really counting on you.
martin
sources for exgigdigeometry::beginpaint are in extensions\exrender\win\exgigdigeometry.cpp
you may place a breakpoint there to see what's wrong.
vladimir
ok, i got it
hello vladimir
while debugging in exgigdigeometry.cpp i found out, that i had not set the logical palette. that's why i got the access violation...
after adding this code...
code:
odcolorref bg = odrgb(255,255,255); // palette background
mykeeper.pcontext->setpalettebackground(bg);
const odcolorref* palette = odcmacadpalette(bg);
mykeeper.m_pdevice->setlogicalpalette(palette, 256);... it finally worked and i saw the drawing displayed in the control!
thank you vladimir, you helped me help myself
now i'll have to catch up for the lost time, highly motivated of course.
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 11:58 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多