Using U3D in .Net

Rob Ebbers
2011-05-10
2013-05-28
  • Rob Ebbers

    Rob Ebbers - 2011-05-10

    Hi all,

    I want to use these libraries in my (managed) .NET program. I'm using mvid's latest sources. Sadly, I can't get them to work. I've tried several things:

    1. Since .NET doesn't support the FastCall calling convention, I tried recompiling all libraries using StdCall by changing the #DEFINEs in IFXAPI.h from __fastcall into __stdcall, but after succesful compilation, even the HelloWorld app crashes.

    2. I wrote an unmanaged wrapper class for calling the IFXCOMInitialize, IFXCreateComponent and IFXCOMUninitialize methods. This wrapper class is able to do the fastcalls, but this also doesn't work, probably because all subsequent method calls on the components created (e.g. pCoreServices->Initialize(IFXPROFILE_BASE from HelloWorld.cpp) are also declared as __fastcall. I get tons of warnings like this: "warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'", because the libraries are compiled with __fastcall.

    Anyone has any idea what to do?
    Has anyone managed to get these libraries working in a .NET app?

    Regards,
    Rob

     
  • Michail Vidiassov

    >  I tried recompiling all libraries using StdCall by changing the #DEFINEs in IFXAPI.h from __fastcall into __stdcall, but after succesful compilation, even the HelloWorld app crashes.

    Did you try debugging?
    MSVC (while debugging HelloWorld) complains at runtime "The value of ESP was not properly saved across a function call." at IFX memory allocation call and suggests that calling a routine using wrong calling convention may be the reason. I do not know anything about calling conventions, but at least that is a C++ problem. NET is completely foreign to me.

    PS. If your 3D output requirements are only basic, there is an option of using PRC output routines from Asymptote project.
    They fit into a couple of simple C++ files, so they can be easily adapted to your requirements.

     
  • Rob Ebbers

    Rob Ebbers - 2011-05-11

    Thanks for your reply mvid.

    Did you try debugging?

    I did, and got the same error as you have encountered. BTW, compiling using __cdecl calling conventions did work, but still I can't get the libraries to work in .NET. I suppose .NET doesn't like calling methods of unmanaged objects outside the managed heap, like

    pCoreServices->Initialize(IFXPROFILE_BASE)
    

    and

    pViewNode->SetSceneGraph(pSceneGraph)
    

    , even though they ought to be properly created by the libraries. I don't know enough about .NET either to get this to work in a reasonable amount of time I'm afraid.

    I think I'll check out the PRC routines you mentioned, as I only want to export not-so-complex 3D models to a 3D PDF.

     
  • Michail Vidiassov

    > I think I'll check out the PRC routines you mentioned,
    E-mail me at master at  iaas.msu.ru for current code.

     
  • Michail Vidiassov

    The following patch fixes __stdcall calling bug.

    --- IFXCoreStatic.cpp.org   2009-05-11 04:55:43.000000000 +0400
    +++ IFXCoreStatic.cpp   2011-05-12 08:12:10.000000000 +0400
    @@ -133,6 +133,9 @@
                                 IFXAllocateFunction*    pAllocateFunction,
                                 IFXDeallocateFunction*  pDeallocateFunction,
                                 IFXReallocateFunction*  pReallocateFunction );
    +    typedef void*     ( IFXAPI JFXAllocateFunction )( size_t byteCount );
    +    typedef void      ( IFXAPI JFXDeallocateFunction )( void* pMemory );
    +    typedef void*     ( IFXAPI JFXReallocateFunction )( void* pMemory, size_t byteCount );
     }
    
    @@ -146,9 +149,9 @@
     static IFXCOMInitializeFunction      *gs_pIFXCOMInitializeFunction      = NULL;
     static IFXCOMUninitializeFunction    *gs_pIFXCOMUninitializeFunction    = NULL;
     static IFXCreateComponentFunction    *gs_pIFXCreateComponentFunction    = NULL;
    -static IFXAllocateFunction           *gs_pIFXAllocateFunction           = NULL;
    -static IFXDeallocateFunction         *gs_pIFXDeallocateFunction         = NULL;
    -static IFXReallocateFunction         *gs_pIFXReallocateFunction         = NULL;
    +static JFXAllocateFunction           *gs_pIFXAllocateFunction           = NULL;
    +static JFXDeallocateFunction         *gs_pIFXDeallocateFunction         = NULL;
    +static JFXReallocateFunction         *gs_pIFXReallocateFunction         = NULL;
     static IFXRegisterComponentFunction  *gs_pIFXRegisterComponentFunction  = NULL;
     static IFXGetMemoryFunctionsFunction *gs_pIFXGetMemoryFunctionsFunction = NULL;
     static IFXSetMemoryFunctionsFunction *gs_pIFXSetMemoryFunctionsFunction = NULL;
    @@ -198,7 +201,7 @@
         if( IFXSUCCESS( result ) )
         {
           gs_pIFXAllocateFunction =
    -        ( IFXAllocateFunction* ) s_coreLib.GetFuncPtr( "IFXAllocate" );
    +        ( JFXAllocateFunction* ) s_coreLib.GetFuncPtr( "IFXAllocate" );
           if ( NULL == gs_pIFXAllocateFunction )
             result = IFX_E_INVALID_POINTER;
         }
    @@ -206,7 +209,7 @@
         if( IFXSUCCESS( result ) )
         {
           gs_pIFXDeallocateFunction =
    -        ( IFXDeallocateFunction* ) s_coreLib.GetFuncPtr( "IFXDeallocate" );
    +        ( JFXDeallocateFunction* ) s_coreLib.GetFuncPtr( "IFXDeallocate" );
           if ( NULL == gs_pIFXDeallocateFunction )
             result = IFX_E_INVALID_POINTER;
         }
    @@ -214,7 +217,7 @@
         if( IFXSUCCESS( result ) )
         {
           gs_pIFXReallocateFunction =
    -        ( IFXReallocateFunction* ) s_coreLib.GetFuncPtr( "IFXReallocate" );
    +        ( JFXReallocateFunction* ) s_coreLib.GetFuncPtr( "IFXReallocate" );
           if ( NULL == gs_pIFXReallocateFunction )
             result = IFX_E_INVALID_POINTER;
         }
    
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks