What i wanted to ask here is that is it possible for me to create Static Library Using vc++ ( coz its a lot Easy :grin: )

and then use those static (dynamic will also do ;) ) with MASM to compile and use those functions in My asm

Posted on 2004-04-12 12:10:24 by telophase
Here is a small example:

int addnumbs(int x,int y)
return (x+y);

char *lcase(char *str)
char *temp=str;
if (*str>64 && *str<91) *str|=32;
return temp;

.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib

includelib sample.lib


format1 db '80+20=%d',13,10,0
msg db 'HELLO WORLD!',0
temp db 100 dup(?)
invoke addnumbs,80,20
invoke wsprintf,ADDR temp,ADDR format1,eax
invoke StdOut,ADDR temp
invoke lcase,ADDR msg
invoke StdOut,eax
invoke ExitProcess,0
END start

Building the executable:

Cl /Ic:\progra~1\micros~2\vc98\include /c /Zl /Ogtyb2 /Gs /G6 /Gz /Zp1 /Foaddnumbs.obj addnumbs.c
Cl /Ic:\progra~1\micros~2\vc98\include /c /Zl /Ogtyb2 /Gs /G6 /Gz /Zp1 /Folcase.obj lcase.c

\masm32\bin\link -lib addnumbs.obj lcase.obj /out:sample.lib

\masm32\bin\ml /c /coff Masmvc.asm
\masm32\bin\link /SUBSYSTEM:CONSOLE Masmvc.obj
Posted on 2004-04-12 13:09:01 by Vortex
but still one question is hanging in my head cant i straight forward create a staic library by selecting the WIN32

Static Library option in the wizard itself.

Also my vc++ code includes WIN32 Api's like MessageBox, CreateFileA etc...

so can it stil work out??
Posted on 2004-04-12 13:19:24 by telophase
Hi telophase,

You can create a static library by selecting the WIN32 Static Library option in the wizard.

About Win32 API functions, you can use any of them with your Asm&VC project. The only trick is to specify the required import libraries at the linking stage. Another thing, be carefull with the MS libraries libc.lib and oldnames.lib, it might be possible to use other libraries with these ones. You can use easily the C run-time DLLs crtdll.dll and msvcrt.dll
Posted on 2004-04-12 13:29:00 by Vortex
I have attached my static lib and the .asm file which tries to call it but it dosent work can u tell me why?

Plz see the attached file thankyou :stupid:

the static1 folder in the zip file contains my vc++ project and static.am contains my calling procedure

when ever i try to compile using MASM i get linker error saying:

'Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.

Assembling: F:\masm32\_MY_PROJECTS\Static_Lib_Tst\static.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

static.obj : error LNK2001: unresolved external symbol _Msg@0
static.exe : fatal error LNK1120: 1 unresolved externals
Link error
Press any key to continue . . .'
Posted on 2004-04-12 20:54:55 by telophase
Remember to declare your procedures as WINAPI, or use a .def file (if you are creating a dll) to create correct names for your export
Posted on 2004-04-13 01:11:10 by greenant
I've made two little changes and now it links perfectly:

1. First I've changed the parameter passing convention to stdcall (Windows and MASM default)like this in StdAfx.cpp :

extern "C" int __stdcall Msg(void)
return 0;

2. I've replaced the start point like this so the linker don't complain anymore about not finding main:


; ?????????????????????????????????????????????????????????????????????????

invoke Msg
invoke ExitProcess,0

; ?????????????????????????????????????????????????????????????????????????

end main


Posted on 2004-04-13 02:53:08 by Eternal Idol Birmingham
Thankyou for u r help but can i also impliment the below example using the above mentioned method




actually i want to use the PE file format functions which are available in

Header: Declared in imagehlp.h.
Import Library: Use imagehlp.lib.

so can this be implemented???????
Posted on 2004-04-13 06:38:31 by telophase
I don't know what you want to do exactly...

Do you want to set up the entry point in the C code? In the static library?

Do you want to call some functions dealing with imagehlp from assembly that are inside the C code?

I think that you can use the imagehlp both from the asm executable and from the C static library.


Posted on 2004-04-13 06:45:06 by Eternal Idol Birmingham
i want to use a inbuilt function MapAndLoad in the imagelib and then i wil return the entry point of the PE file

which i wil use in asm:grin:
Posted on 2004-04-13 06:49:45 by telophase
You shouldn't have any problem, remember that the getentrypoint() return value will be in the eax register.


Posted on 2004-04-13 06:52:39 by Eternal Idol Birmingham
Thankyou very much for your help.:alright:
Posted on 2004-04-13 07:22:20 by telophase
No problem, you are welcome, by the way where are you from?


Posted on 2004-04-13 08:50:45 by Eternal Idol Birmingham
From India and U?
Posted on 2004-04-13 08:57:25 by telophase
I'm from Argentina but I'm living in Spain right now :)


Posted on 2004-04-13 08:58:50 by Eternal Idol Birmingham
U got any yahoo! id or something for contacting u?
Posted on 2004-04-13 09:00:19 by telophase
I'll send you a Private Message ;)


Posted on 2004-04-13 09:04:33 by Eternal Idol Birmingham
The method u specified didnt work for by modifying the function to extern "c" int __stdcall
Posted on 2004-04-14 05:29:38 by telophase
The method u specified didnt work for me by modifying the function to extern "c" int __stdcall
Posted on 2004-04-14 05:29:46 by telophase
when i compile it no probs but when i link it , cant link get i get linker erroe saying that some "libcd.lib" is missing
Posted on 2004-04-14 05:39:04 by telophase