title: Calling MASM32 procedure from .c
body: <p>I am using visual studio at the moment. I need to build a win32 application and need to call a procedure from a C function but I am always getting a build error:</p>
  
  <p>Error   3   error LNK1120: 1 unresolved externals   </p>
  
  <p>I have reduced everything down to a simple main function and simple .asm file with one procedure and I am still getting the same build (or rather link) error. I'm at a loss.</p>
  
  <p>Both are using the cdecl convention.</p>
  
  <p>The MASM32 code (in its own .asm file):</p>
  
  <pre><code>.MODEL FLAT, C
  .DATA              
  
  .CODE      
  
  PUBLIC memory_address
  
  memory_address PROC 
  
      mov eax, DWORD PTR [esp] 
  
      ret
  
  memory_address ENDP
  
  END
  </code></pre>
  
  <p>It assembles fine. The .c file:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;malloc.h&gt;
  #include &lt;stdio.h&gt;
  
  extern int memory_address(int* ptr);
  
  void main()
  {
      int *ptr = (int*)malloc(sizeof(int));
  
      memory_address(ptr);
  
      while (1) {}
  
      return;
  }
  </code></pre>
  
  <p>No idea why this is happening. I have been using MASM happily for 64bit application for about a year or so with no problems. But I have to make a 32bit application I am having no luck calling the MASM32 proc memory_address().</p>
  
  <p>I hasten to add I know how to do this in NASM for 32 bit applications and I know how to do it for 64bit applications using MASM. This is strictly a MASM32 issue. Any suggestions would be great - but only for MASM32. Thanks.</p>