从VB6调用C ++ DLL传递垃圾数据作为参数吗?

时间:2018-11-27 19:14:07

标签: vb6 vc6


gcloud alpha compute start-iap-tunnel <destination VM> 
<destination port> --zone=us-west1-a 
--project=<project where destination VM resides>

在调用VC调试器(例如1.34867e-308、3.49732e-88等)之前,在VB调试器中看起来不错,然后再调用。

对于可能原因的任何想法,我将不胜感激。我已经为此苦苦挣扎了几天。顺便说一句,我不选择在遗留代码中工作!

下面是C标头原型,.DEF定义和VB声明。

头文件定义:

VC functions all use _stdcall
functions exported using .def file 
     (e.g.  AliasFuncName = _FuncName@NumCallArgBytes)
Existing C DLL was revised to have some new call arguments 
  (revised function names, built to new dll name)

Functions with unrevised call arguments work when calling the new DLL
Functions with revised call arguments do not work when calling the new DLL
   (all call arguments are garbage on entry)
Call arguments are several input doubles and a few return double*

Prototype.h call definition matches c source code definition
Visual Basic declarations to new DLL match in style those to the old DLL
   (several ByVal double input args and a few ByRef return args)

.DEF文件定义:

LONG _stdcall SYSDll_FRoulSlideXa(
    double ATest, double Hc, double Hivr,
    double Eeq, double Rx, double Rk,
    double L, double U, double SlRol,
    double R, double Wlc, double Wpc,
    double Mu, double MuOil, double Cor2AL,
    double Fs, double Ft,
    double *FRoul, double *FSlid);

VB6声明:

LIBRARY "SYSx32d10a"

DESCRIPTION 'SYSx Dlls'

EXPORTS
    SYSDll_FRoulSlideXa = _SYSDll_FRoulSlideXa@144

注意:我已经在最后两个参数上尝试了显式Declare Function SYSDll_FRoulSlideXa Lib "SYSX32D10A.DLL" ( _ ByVal ATest As Double, ByVal Hc As Double, ByVal Hivr As Double, _ ByVal Eeq As Double, ByVal rx As Double, ByVal Rk As Double, _ ByVal L As Double, ByVal U As Double, ByVal SlRol As Double, _ ByVal r As Double, ByVal Wlc As Double, ByVal Wpc As Double, _ ByVal Mu As Double, ByVal MuOil As Double, ByVal Cor2AL As Double, _ ByVal Fs As Double, ByVal Ft As Double, _ FRoul As Double, FSlid As Double) ,而不是依靠默认的传递约定为ByRef

1 个答案:

答案 0 :(得分:6)

您的VB Declare不包含该函数的返回类型。除非您没有显示DEFxxx语句,否则表示VB期望Variant。由于Variant函数使用隐藏参数返回其值,因此堆栈将未对齐。仅此一项就可以引起您所见。

解决方案是将正确的返回类型添加到VB Declare