Register | Login
Forum Index > Source Help > import undecorated c++ function
Author Message
Pages: 1 2 3
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[1289] - posted: 2012-12-26 18:18:00

yes you was correct .

here is the prototype of the function
Code:
BBDECL int    BBCALL RenderWorld(float timeSinceLastFrame = 0.0);


I have update it but still crashed.
here is the new code.
Code:
//****************************************//
//           ************                 //
//      ***MagicPro library***            //
//           ************                 //
//****************************************//
program WIN32GUI 'MagicPro Test #1';

#include 'console.zir';
#include 'ch.zir';

const KC_ESCAPE = 0x01;
imports('MagicPro.dll') 
{  
  procedure z_init = ('_z_init@4')(char* Titel); cdecl; 
  procedure Graphics3D = ('_Graphics3D@20')(Dword Width,Height,depth; boolean fullScrn,VSync);  cdecl;
  procedure z_setAmbientLight = ('_z_setAmbientLight@12')(single red,green,blue); cdecl;  
  procedure setMediaDir = ('_setMediaDir@8')(char* name;boolean recursive); cdecl;
  function  OIS_isKeyDown = ('_OIS_isKeyDown@4')(int32 key): boolean; cdecl;
  procedure RenderWorld = ('_RenderWorld@4')(single timeSinceLastFrame); cdecl;
  procedure Sync(); cdecl;
  procedure EndGraphics = ('_EndGraphics@0')(); cdecl;
}  

    z_init('MagicPro Test #1');
    Graphics3D(800,600,32,false,false);

    z_setAmbientLight(30,30,50);

    setMediaDir('ZipMedia.zip',true);
    setMediaDir('media',true);
    
    while(!OIS_isKeyDown(KC_ESCAPE))
     {
        
        RenderWorld(0);
      Sync();
     }
 
    EndGraphics(); 
ExitProcess(0);


http://www.freewebs.com/ogremagic/index.htm
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[1290] - posted: 2012-12-26 19:11:17

i have modified the test program , to discover where it crashed.

here is the modification
Code:
//****************************************//
//           ************                 //
//      ***MagicPro library***            //
//           ************                 //
//****************************************//
program WIN32CUI 'MagicPro Test #1';

#include 'console.zir';
#include 'ch.zir';

const KC_ESCAPE = 0x01;

imports('msvcrt.dll') 
{
  function printf(char* format[]): Int32; cdecl;
}


imports('MagicPro.dll') 
{  
  procedure z_init = ('_z_init@4')(char* Titel); cdecl; 
  procedure Graphics3D = ('_Graphics3D@20')(Dword Width,Height,depth; boolean fullScrn,VSync);  cdecl;
  procedure z_setAmbientLight = ('_z_setAmbientLight@12')(single red,green,blue); cdecl;  
  procedure setMediaDir = ('_setMediaDir@8')(char* name;boolean recursive); cdecl;
  function  OIS_isKeyDown = ('_OIS_isKeyDown@4')(int32 key): boolean; cdecl;
  procedure RenderWorld = ('_RenderWorld@4')(single timeSinceLastFrame); cdecl;
  procedure Sync(); cdecl;
  procedure EndGraphics = ('_EndGraphics@0')(); cdecl;
}  

    z_init('MagicPro Test #1');
    Graphics3D(800,600,32,false,false);

    z_setAmbientLight(30,30,50);

    setMediaDir('ZipMedia.zip',true);
    setMediaDir('media',true);
    
    int32 k = 0;
    while(!OIS_isKeyDown(KC_ESCAPE))
     {
        printf('%d\n', k);
        RenderWorld(0);
        printf('RenderWorld is ok\n');
      Sync();
      k++;
     }
 
    EndGraphics(); 
ExitProcess(0);


and found that it crashed after 7 iterations.
also the crashed was in Sync function and here is the prototype of it
Code:
BBDECL void Sync();


so what code be the reason of crashing?

http://www.freewebs.com/ogremagic/index.htm
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[1291] - posted: 2012-12-26 22:05:16

BTW , here is the cmd line of MSVC++10

cl.exe /nologo /W3 /MD /EHs /O2 /DNDEBUG /I"C:\Program Files\Microsoft Visual Studio 10.0\VC\include" /I"C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include" /I..\..\..\..\OgreSDK_vc10_v1-8-0\boost /I..\..\..\include /I..\..\..\..\OgreSDK_vc10_v1-8-0\include /I"C:\Program Files\Microsoft Visual Studio 10.0\VC\include" /c DBTest2.cpp /Foobj\Release\DBTest2.obj



does the compiler option "/MD" (multi threaded runtime library) itself is the reason of crashing?

http://www.freewebs.com/ogremagic/index.htm
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1292] - posted: 2012-12-26 22:21:44
There is not really much i can help with since i can't see the code for sync etc but it is possible you are doing something in sync that breaks.

You can try to compile your dll with /MT instead to see if it solves the issue, else if you can send me a setup of your test app, with your dll and the zir code i can take a look when i get a bit free time.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[1293] - posted: 2012-12-27 21:08:14

ok, finally the problem is solved.

any way , can ziron allow optional parameters with import library.

something like this
Code:
procedure RenderWorld = ('_RenderWorld@4')(single timeSinceLastFrame = 0.0); stdcall;


thanks.

http://www.freewebs.com/ogremagic/index.htm
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1294] - posted: 2012-12-27 21:43:51
I'm guessing the problem was the exported functions were stdcall?

actually i think cdecl funcs mangled do not end with param size "@4" etc since ste stackmis handled by the caller

As for default params, it does not already work? I will take a look when i get back in the office

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[1295] - posted: 2012-12-28 12:11:38

yes , the problem wes Stdcall and cdecl.

MagicPro library has many stdcall functions and many c++ classes and c functions.

so i am thinking to make all functions stdcall but for the classes i will see if i can make
their public functions as a stdcall.

BTW , who can i create an instance of C++ class in ziron and call it's function.


http://www.freewebs.com/ogremagic/index.htm
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1298] - posted: 2012-12-28 15:50:45
Right now i have not looked much into this since c memory management is very different, this is a feature i plan to look into for Ziron 2, to be able to create c++ compatible classes.

The class would need to be created in ziron and then only the functions would be used from the c++ class, all memory management would need to be localside.

e.g.

Code:
me = new myClass;   // ziron create me
me.mycppFunc();     // cpp interface class function which is passed the mem ptr
delete me;          // ziron delete me


But i will first look into this for Ziron 2.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1 2 3
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 5 user(s) online. 0 member(s) and 5 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd