Back to a question of few days ago, I retrieved from MS a file called AsmClock that show how to call C functions from an Asm program (in this example the C function are sprintf from stdio.h, time and datetime from time.h).
Included are inc files generated with h2inc...

The problem is the program (a translation of an original Petzold code in C) is old 16 bits Windows, and I can't make any progress with it !!

I tried to write a personal inc file only for times function using masm32 syntax (PROTO and so on), but when I assemble my programs, the linker cannot find any reference to extern C functions.

Any suggestion ??

Thanx, Saiwa

P.S. Here is the proggie...
Posted on 2001-11-15 02:53:00 by Saiwa
I just assembled and linked your prog.

Problems were:

1. assemble error because of definition of "mm" in struct METAFILEPICT in windows.inc. Changed this to "mm_" (may be mm is a reserved word now)

2. linked your prog with libs "libw.lib" and "slibcew" (your prog is a 16 bit win app, as you may have noticed). No errors.

No problems when running your prog.

Its attached
Posted on 2001-11-15 04:23:19 by japheth
OK, thanx for the ready answer.

But what if I want to include some C function in my Asm32 programs (for example a function from libc.lib).

Here the real question is: to use a lot of useful library written only for C (i.e. math, statistic, graphic and so on) should I really use C ???

I think not, since at the end all craps become simply bits...

Sometime ago I needed a function such as asctime so I disassebled it, and recoded (with only minor modification) as a Asm32 routine... everything works perfectly !!!

Have I to do it with all routines... there should be a better solution.

Thanx again, Saiwa
Posted on 2001-11-15 18:25:40 by Saiwa
Using C from assembly isn't too hard. There's a few catches. First,
you must make sure the C stuff is exported with undecorated names...
this is mostly an issue for C++ source, where you'll have to define
function prototypes as extern "C" void myFunc(void);
(add appropriate return type, func name, and arguments of course ;) ).
Then you have to set up a proto in masm, with the correct calling
convention. For the C function "void myFunc(int x);", the masm proto
should look something like


myFunc PROTO C :DWORD

... and you should hopefully be all set :)
Posted on 2001-11-15 18:51:19 by f0dder
Thanx F0dder,

glad You're back with us :alright:

I will try and maybe tell you about results.

Bye, Saiwa
Posted on 2001-11-15 18:56:10 by Saiwa