几何尺寸与公差论坛------致力于产品几何量公差标准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-06, 05:13 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】load wingdi module from managed dll

load wingdi module from managed dll?
load wingdi module from managed dll?
hello
i get an oderror "the specified module could not be found. wingdi_2.06_9.gs" when trying to load the module from a managed dll (mixed mode). i use the dwg-libraries (dll) and the preprocessor directive "_tookit_in_dll" is set.
the dll contains a custom windows forms control which is used in a .net application to display a dxf drawing.
i have another, smaller application where the module can be loaded and the drawing is actually displayed. the code is pretty much the same. i don't understand why the module cannot be loaded.
what i've tried / checked so far:
- use the right libs/dlls, all the binaries are in the same directory.
- add an external manifest file for wingdi.gs(will it also work for debug?).
is there a known problem loading a module from a managed dll i should know about? do you have any suggestions what i might be missing?
the manifest file as recommended in this forum:
code:
<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestversion='1.0'>
<trustinfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedprivileges>
<requestedexecutionlevel level='asinvoker' uiaccess='false' />
</requestedprivileges>
</security>
</trustinfo>
<dependency>
<dependentassembly>
<assemblyidentity type='win32' name='microsoft.vc90.crt' version='9.0.21022.8' processorarchitecture='x86' publickeytoken='1fc8b3b9a1e18e3b' />
</dependentassembly>
</dependency>
</assembly>-------------------edit:
i also tried this debug version of manifest file, the module still couldn't be loaded:
code:
<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestversion='1.0'>
<trustinfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedprivileges>
<requestedexecutionlevel level='asinvoker' uiaccess='false' />
</requestedprivileges>
</security>
</trustinfo>
<dependency>
<dependentassembly>
<assemblyidentity type='win32' name='microsoft.vc90.debugcrt' version='9.0.21022.8' processorarchitecture='x86' publickeytoken='1fc8b3b9a1e18e3b' />
</dependentassembly>
</dependency>
</assembly>-------------------edit:
the code where i initialize the od-libraries. the odcontainer class is a native c++ class which stores smartpointers to the database etc. the constructor is called by the windows forms control.
code:
#pragma once
#include <vcclr.h>
#include "odservices.h"
#include "dbdatabase.h"
#include "dbfiler.h"
#include "dbgsmanager.h"
#include "rxvariantvalue.h"
#include "gicontextfordbdatabase.h"
#include "rxdynamicmodule.h"
#include "colormapping.h"
#include "abstractviewpe.h"
#include "odcontainer.h"
void odgsinitialize();
void odgsuninitialize();
using namespace system;
using namespace system::runtime::interopservices;
namespace dxfviewer{
odservices services;
public ref class odcontext
{
public:
odcontext(void){
con = new odcontainer();
odinitialize(&services);
drawable = false;
}
~odcontext(){
oduninitialize();
}
boolean isdrawable()
{
return drawable;
}
void draw( intptr hdc, int width, int height ){
try{
if( this->isdrawable() ){
odint32 handlevalue = (odint32)hdc.toint32();
odrxdictionaryptr pproperties = con->gsdevice->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));
}
odcolorref bg = odrgb(255,255,255); // palette background
con->gicontext->setpalettebackground(bg);
const odcolorref* palette = odcmacadpalette(bg);
con->gsdevice->setlogicalpalette(palette, 256);
con->gsdevice = oddbgsmanager::setupactivelayoutviews(con->gsdevice, con->gicontext);
// code to render the drawing
odgsdcrect gsrect(0, 256, 256, 0); // you'll have to provide the dimensions of the output device
con->gsdevice->onsize(gsrect);
con->gsdevice->ondisplaychange(16, 256, 256); // same as above
odgsviewptr pview = con->gsdevice->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);
con->gsdevice->invalidate(gsrect);
if( con->gsdevice->isvalid() ){
con->gsdevice->update();
}
}
}catch( oderror e ){
odstring err = e.description();
}
}
system::string^ opendrawing( string^ filename )
{
pin_ptr<const wchar_t> str = ptrtostringchars(filename);
odstring dxfdrawing = str;
try{
con->database = services.readfile( dxfdrawing, false, false, oda::ksharedenyno );

odstring modulename = odstring(l"wingdi.gs");
odgsinitialize();
con->gicontext = odgicontextfordbdatabase::createobject();
con->gicontext->setdatabase(con->database);
con->gicontext->enablegsmodel(true);
odgsmoduleptr gsmodule = :drxdynamiclinker()->loadmodule( modulename,false );
if (gsmodule.isnull()) {
throw gcnew exception("error loading module");
}
if (con->database.isnull()) {
throw gcnew exception("error opening database");
}
con->gsdevice = gsmodule->createdevice();
if (con->gsdevice.isnull()) {
throw gcnew exception("error creating gdi render device");
}
drawable = true;
wchar_t* retstr = l"";
string^ ms = marshal:trtostringuni((intptr)retstr);
return ms;
}catch(oderror e){
std::wstring tempstr = e.description();
const wchar_t* retstr = tempstr.c_str();
string^ ms = marshal:trtostringuni((intptr)(void*)retstr);
return ms;
}catch(exception^ e){
return e->message;
}
}
private:
odcontainer * con;
bool drawable;
};
};this problem is quite urgent, i need to have that viewer running by the end of the week and there is still a lot of work to be done...
please spare a minute or two for a quick response.
thanks
martin
last edited by martin.affolter@ntb.ch; 9th december 2008 at 08:41 amfff">.
try to call ::loadlibrary with the full path to the gs module and see what result would be returned (that is - what getlasterror() will return.)
try to add manifest to an application, not to the module.
vladimir
this is what i get when calling ::loadlibrary() and getlasterror():
quote:
error_mod_not_found
126
0x7e
the specified module could not be found.
i also tried calling another dll (zlib.dll) just to make sure the path is ok. loading zlib.dll worked, returncode was "0".
code:
//test
::loadlibrary( l"d:\\dxfviewerdotnet\\debug\\wingdi_2.06_9.gs" );
//::loadlibrary( l"d:\\dxfviewerdotnet\\debug\\zlib.dll" ); //->this works
dword word = getlasterror();
con->gicontext->enablegsmodel(true);
odgsmoduleptr gsmodule = :drxdynamiclinker()->loadmodule( modulename,false );ok, i will try to add a manifest-file to the application. i will have to look up, how to do that correctly and then post the results immediately. in the meantime, if you know anything else i can try, please let me know.
thanks
i don't seem to understand manifest-file handling...
i have a csharp application (simple windows form). this project builds an executable. the project's properties page doesn't offer a lot of manifest options.
then there is the mixed dll, with a windows forms control and the pointers to the dwg-objects.
where should i add a manifest file and what would it look like? i understand the manifest file gives you the ability to list dependent assemblies. is that what you mean with your second tip?
i've tried a few things, without any results... don't know what to do, hope you'll come back at me.
---------------edit-----------------
this works (errorcode 0) but will not help me any. maybe this gives you an idea? i forgot to tell you that the simple application is mc++ only (all in one project, module can be loaded) and the application with loading problems is c# with mc++ dlls.
code:
hmodule libhandle = ::loadlibraryex( l"d:\\dxfviewerdotnet\\debug\\wingdi_2.06_9.gs", null, dont_resolve_dll_references );
dword word = getlasterror();about the last parameter:
quote:
if this value is used, and the executable module is a dll, the system does not call dllmain for process and thread initialization and termination. also, the system does not load additional executable modules that are referenced by the specified module.
i assume that the dllmain() method of wingdi.gs does someting that .net cannot handle? what else can i try? i'm running out of time...
---------------2nd edit-----------------
now it's getting interesting. i replaced the c# windows forms application with a mc++ windows forms application. the windgdi module can now be loaded without any problems. unfortunately, the gui is already implemented in c#, so i have to find a way to load the module in a c# application ( c#windowsform->mc++windowscontrol->wingdi-module ).
how can i achieve that?
---------------3rd edit-----------------
the module can be loaded in a c# appliaction when starting the application without debugging...(ctrl+f5). it is not a solution, but i will try to continue that way...
help is always welcome, i'll check this post all day long...
last edited by martin.affolter@ntb.ch; 10th december 2008 at 02:28 amfff">.
manifest can be external - that is: have 3 copies of the xml you quoted in the fist post, with the names of the exceutable and 2 dlls, with ".manifest" attached, in the executable folder. that is, if your application is called, say "myapp.exe", manifest should be called "myapp.exe.manifest". the same with dlls.
if it will help, remove unnecessary manifests one by one.
vladimir
i created the c# application without manifest file and then manually added the manifest example file to the .exe's directory. when starting the application from vs2008 without vhost, the module can be loaded.
this seems to work. once again i stumbled over the manifest issue. if you know a good site where manifest file handling is documented, please let me know. i'd be happy to learn and avoid any manifest-related problems...
vladimir, thanks for your help!
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】linking in dll yang686526 DirectDWG 0 2009-05-06 05:07 PM
【转帖】error while linking using mfc static library vc 96.00 yang686526 DirectDWG 0 2009-05-05 09:49 AM
【转帖】dll学习(资料收集) huangyhg vc编程 0 2008-05-17 09:24 PM
最难清除木马 Dll木马揭秘 huangyhg vc编程 0 2007-04-12 07:31 PM
regsvr32.exe的使用 cam 论坛管理 0 2007-02-27 11:07 PM


所有的时间均为北京时间。 现在的时间是 01:57 AM.


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