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!