如何将数组从C ++传递给汇编程序DLL?

时间:2014-12-16 18:52:29

标签: c++ assembly

我想从c ++传递4个数组,2个数组是2D,2个数组是正常的。我在c ++中有这段代码:

typedef int(*DLLFunc)(double**, double*, double**, double*, int);

// main和其他一些代码

hDll = LoadLibrary("FibAsmLib");

    if (hDll != NULL){

        myAsmProc = (DLLFunc)GetProcAddress(hDll, "MyProc");

        if (myAsmProc != NULL){
            result = myAsmProc(arrayA, arrayB, arrayAlfa, arrayBeta, rowA);
        }
        cout << "Result from library: " << result;
    }

这在汇编程序中:

.486
.model flat, stdcall
.data
.code

PUBLIC MyProc
MyProc proc w: DWORD, x:DWORD, y:DWORD, z:DWORD, e:DWORD
mov eax, 5
ret
MyProc endp
end

当我运行程序时,我有一个奇怪的错误:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

你有什么建议吗?

1 个答案:

答案 0 :(得分:2)

您告诉汇编程序,导出的过程遵循stdcall调用约定,但C程序认为它是cdecl(如果您没有指定特定的调用约定VC ++假定为cdecl)。修复任何一方,问题应该消失。