The MASM Forum Archive 2004 to 2012

Specialised Projects => Compiler Based Assembler => Assembler With Microsoft Visual C => Topic started by: a_h on July 14, 2005, 06:08:31 PM

Title: accessing external global variables with masm
Post by: a_h on July 14, 2005, 06:08:31 PM
Hi!

I'm sorry that I double post (similar posting in the campus), but I think it's better suited here for the people to read it that might know an answer.

Currently I've some masm-assembly as .asm file that is part of a tiny Visualc++6-project. In the .cpp file I declare global variables N, B of type unsigned int that I want to access:

However
---------------------------------
.686
.model flat, stdcall
option casemap :none

Extern _B:DWORD
Extern _N:DWORD

.code
...
--------------------------------
doesn't link. It doesn't work with and without the leading underscores and neither with 'C' instead of stdcall.

How can I access them?

Thanks a lot for your reply! Hannes
Title: Re: accessing external global variables with masm
Post by: hutch-- on July 17, 2005, 07:21:53 AM
Hannes,

MASM has the correct notation to read an external value with EXTERNDEF but you will have to read up on the VC compiler to find the method of making a global variable visible. In MASM you use PUBLIC and this may be a hint of what to do in VC.
Title: Re: accessing external global variables with masm
Post by: tenkey on July 25, 2005, 11:58:27 PM
In your .cpp file declare your variables with extern "C". Make sure you have the correct case, as the default for linking C++ code is case-sensitive names.

extern "C" unsigned int N, B;

As a further check, look at the linker error messages, as they will tell you what names the C++ compiler created for linking purposes.
Title: Re: accessing external global variables with masm
Post by: Vortex on July 26, 2005, 10:07:54 AM
Thanks tenkey, extern "C" is the main trick :U