Pelles C forum

C language => Beginner questions => Topic started by: Bagamut on June 10, 2011, 08:22:35 PM

Title: Need Help To convert C++ header to C
Post by: Bagamut 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. (http://www.mediafire.com/?ads7z6qx1p1pf8u)
Title: Re: Need Help To convert C++ header to C
Post by: TimoVJL on June 11, 2011, 12:01:01 AM
For start try this:
Use compiler options -Ze -Zx
// 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
Title: Re: Need Help To convert C++ header to C
Post by: Bagamut on June 11, 2011, 12:52:20 PM
Quote from: timovjl on June 11, 2011, 12:01:01 AM
For start try this:
Use compiler options -Ze -Zx
// 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?
Title: Re: Need Help To convert C++ header to C
Post by: TimoVJL on June 11, 2011, 01:02:14 PM
QuoteWhy 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
Title: Re: Need Help To convert C++ header to C
Post by: hermandez 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.