NO

Author Topic: Need Help To convert C++ header to C  (Read 3225 times)

Bagamut

  • Guest
Need Help To convert C++ header to C
« on: June 10, 2011, 08:22:35 PM »
Hello everybody.

I'm beginner in C programing and need some help with converting C++ header to C.

I have great game engine that was written in Visual C++, all functions use stdcall calling conv. Then i try building project, compiler outputs errors about defined functions.

Here dll, lib & header.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Need Help To convert C++ header to C
« Reply #1 on: June 11, 2011, 12:01:01 AM »
For start try this:
Use compiler options -Ze -Zx
Code: [Select]
// Delaration & call macros
#ifdef __cplusplus
#define X3DDECL extern "C" __declspec(dllexport)
#else
#define X3DDECL
#endif
#define X3DCALL _stdcall

#ifndef bool
#define bool BOOL
#endif

#ifndef true
#define true TRUE
#endif

#ifndef false
#define false FALSE
#endif
« Last Edit: June 11, 2011, 12:10:48 AM by timovjl »
May the source be with you

Bagamut

  • Guest
Re: Need Help To convert C++ header to C
« Reply #2 on: June 11, 2011, 12:52:20 PM »
For start try this:
Use compiler options -Ze -Zx
Code: [Select]
// Delaration & call macros
#ifdef __cplusplus
#define X3DDECL extern "C" __declspec(dllexport)
#else
#define X3DDECL
#endif
#define X3DCALL _stdcall

#ifndef bool
#define bool BOOL
#endif

#ifndef true
#define true TRUE
#endif

#ifndef false
#define false FALSE
#endif

Thanks, it works. But I have a couple more questions. How i should declare a NULL variable? Why when i'm using "int main(int argc, char *argv[ ]) {...}" i have error - POLINK: error: Unresolved external symbol '_WinMain@16'. POLINK: fatal error: 1 unresolved external(s); and if building project using "int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdline, int nCmdShow)" all compiling without any problems?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Need Help To convert C++ header to C
« Reply #3 on: June 11, 2011, 01:02:14 PM »
Quote
Why when i'm using "int main(int argc, char *argv[ ]) {...}" i have error - POLINK: error: Unresolved external symbol '_WinMain@16'. POLINK: fatal error: 1 unresolved external(s)
In that case change linkers Subsystem Type to Console
Linker option: -subsystem:console
May the source be with you

hermandez

  • Guest
Re: Need Help To convert C++ header to C
« Reply #4 on: August 18, 2011, 11:43:18 AM »
There is indeed such a tool, Comeau's C++ compiler. . It will generate C code which you can't manually maintain, but that's no problem. You'll maintain the C++ code, and just convert to C on the fly.