News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

OBJ for C

Started by dedndave, December 24, 2009, 07:53:01 PM

Previous topic - Next topic

dedndave

i want to make a C-callable routine from MASM
i know how to make an OBJ   :bg
my question is, what is the C equiv of PROTO's ?
another one...
is it defined in a .H file ?

ecube

not really sure what you're asking, but you can define your masm function as standard stdcall or change it to C in C you'd define it to something similar to the paramets for instance


strcpyX proto C :DWORD,:DWORD

in C it'd be

strcpyX(char *tobuffer,char *frombuffer);

it's consider standard practice to put the definition in a .H but can be in the .c/.c++ file, doesn't matter. Actually in Visual C I don't think you even need to define the function, just use it, and maker sure the linker knows of the .lib or .obj

your static link library(mylib.asm)

.586
.MODEL FLAT,STDCALL
OPTION CASEMAP:NONE


include \masm32\include\windows.inc
include \masm32\include\kernel32.inc

strcpyX   proto C :DWORD,:DWORD
.code
strcpyX proc tobuf:DWORD,frombuf:DWORD
;whatever
ret
strcpyX endp
End


;build.bat
:MAKE
\MASM32\BIN\ML /c /coff /Cp mylib.asm
\MASM32\BIN\link /SUBSYSTEM:WINDOWS /LIBPATH:c:\masm32\lib /SECTION:.text,RWX mylib.obj
pause


then to use in visual C++ you can either specify in the linker includelibs mylib.lib or you can
#pragma comment(lib, "mylib.lib")
in the source file


example.c

#include <windows.h>
#pragma comment(lib, "mylib.lib")
strcpyX(char *tobuffer,char *frombuffer); //probably not needed
int main()
{
char mybuf[256];
strcpyX(mybuff,"teststr");
return 0;
}

dedndave

thanks, Cube
i think that covers what i wanted to know nicely   :U