I sometimes program with different kinds of languages besides C/C++. These include VB, Quickbasic, 32bit ASM, 16bit ASM, Pascal, etc.
I make functions and have a slew of obj files, and I was thinking, hey wouldn't it be nice to be able to link one of these to a C++ program and call the external function from Main() ?
However, I havent had much success with this sort of thing. I am sure I am doing a few things wrong. Let me give you a very simple example. In this example we have a win32 console app programmed in C++ (I use Microsoft Visual C++ 6.0, and even Borland C++ 5 sometimes, either one is ok.) In the Assembly code file, we have a function called Theproc, which just prints something to the console. (I use Masm32, Nasm, and win32asm, either one is ok)
First is the asm program with our external function.
Code:
.486 ; create 32 bit code
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive
include \masm32\include\windows.inc ; always first
include \masm32\macros\macros.asm ; MASM support macros
; -----------------------------------------------------------------
; include files that have MASM format prototypes for function calls
; -----------------------------------------------------------------
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
; ------------------------------------------------
; Library files that have definitions for function
; exports and tested reliable prebuilt code.
; ------------------------------------------------
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.code ; Tell MASM where the code starts
; ллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл
start: ; The CODE entry point to the program
Theproc proc ; This is our function
print chr$("Hey, this actually works.",13,10)
; exit we don't need the exit since we will be calling from C++ Main()
; and that exits fine
ret ; But we -> DO <- need a return.
Theproc endp
; ллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл
end start ; Tell MASM where the program ends
Ok in the second program, we have our C++ program that calls the Theproc function
Code:
#include <iostream.h>
#include <windows.h>
// THIS is where i would put the extern "C" Theproc() right??
// Or would it be extern "C" _Theproc() ?
int main() // No command line params
{
Theproc();
return 0;
}
So how would I code these to make them linkable to eachother? I would use extern "C" and not __export correct? And what would be the correct way to declare my Theproc function public so main() could call it?
Any help is appriciated.