Need Help To convert C++ header to C

Started by Bagamut, June 10, 2011, 08:22:35 PM

Previous topic - Next topic

Bagamut

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.

TimoVJL

#1
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
May the source be with you

Bagamut

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?

TimoVJL

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
May the source be with you

hermandez

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.