我正在开发一个使用MASM调用某些C++函数的程序。我在一个单独的文件中定义了对2个整数求和并显示输出。
目前,我无法让“main.cpp”运行asmMain()
来从“main.cpp”调用函数。
代码库
; ---------------------------------------
promptFirst PROTO C
promptSecond PROTO C
printInt PROTO C
.586
.model flat, stdcall
.stack 4096
; ---------------------------------------
.DATA
first DWORD 0
second DWORD 0
; --------------------------------
.CODE
asmMain PROC C
mov first, promptFirst
ret
asmMain ENDP
PUBLIC asmMain
END
main.cpp#include <iostream>
using namespace std;
void asmMain();
int promptFirst();
int promptSecond();
void printInt(int myint);
int main() {
asmMain();
}
int promptFirst() {
cout << " The first number = ";
int newint;
cin >> newint;
return newint;
}
int promptSecond() {
cout << "\nThe second number = ";
int newint;
cin >> newint;
return newint;
}
void printInt(int myint) {
cout << myint;
}
我得到的当前代码错误是这样的:关于如何解决此问题的任何提示?
最佳答案
问题是C++编译器mangles the symbols,这是extern "C"
构造背后的原因之一,因此不会使符号困惑。
如果将函数声明为extern "C"
,则编译器将不会修改名称,就像对调用的汇编器函数所做的那样。
关于c++ - 在MASM中调用C++函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28591452/