编辑:已经让这个在32位下工作,我现在正试图让它适用于64位.我已经获得了DLL的源代码,并且DLL和应用程序都被编译为64位.我每次都会遇到访问冲突.这是DLL代码(C在
VisualStudio2005中):
#pragma pack( push,2 ) // Output Results Structure typedef struct tagTVA_RESULTS { int iID; /* Difference ID 1 .. n */ int iLeft; /* Bounding rectangle */ int iRight; int iTop; int iBottom; double dCx; /* Center of gravity */ double dCy; double dMajor; /* Shape information */ double dMinor; double dAngle; /* Rotational information */ int lArea; /* Number of pixels */ int iEdge; /* Set if difference is at the edge of the image */ double dNormalDensity; int iNormalCount; double dDifferenceDensity; } TVA_RESULTS,*PTVA_RESULTS; #pragma pack ( pop )
注意它将包设置为2.我已经尝试在应用程序中将其设置为2,但它失败了.我尝试了其他值,我甚至尝试过不同的值.我已经尝试使用4作为整数大小,8作为双倍大小.但我认为(知识有限)如果两种包装尺寸相同,它应该有效.
此时我怀疑函数是如何调用的.它的第一个参数是指向这些结构数组的指针.应用程序传入数组ByRef的第一个元素,我认为它实现了这一点.但是指向数组的错误指针可以解释症状.这是DLL中的函数定义.
int WINAPI MNtvaAnalyzeVB (TVA_RESULTS *pResults,int iMaxCount)
我的老板认为这可能是一个big/little endian问题,但如果它们都在同一环境中编译,那似乎不太可能.
我该怎么办?
End of edit >>>
我正在将Visual Basic 6.0应用程序转换为VB.NET.我有几个结构传递给外部DLL文件.这不起作用,我感觉这是由于结构没有正确传递.
这是原始结构:
Public Type TVA_PARAMETERS iStandardFilterOnOff As Long iSampleFilterOnOff As Long iDifferenceFilterOnOff As Long iRotationCorrectionOnOff As Long iLocalCorrectionOnOff As Long iStandardAOIx As Long iStandardAOIy As Long iStandardAOIdx As Long iStandardAOIdy As Long iSampleAOIx As Long iSampleAOIy As Long iSampleAOIdx As Long iSampleAOIdy As Long iRepeatHorizontal As Long iRepeatVertical As Long dSensitivity As Double iMergeWidth As Long iMergeHeight As Long iMinimumDifferenceArea As Long iMaximumDifferenceArea As Long End Type如果我在Visual Basic 6.0中对该类型的变量执行LenB,则得到84个字节. (N.B.:我不确定这是否是确定其大小的有效方法.)
我试图将它转换为VB.NET:
Public Structure TVA_PARAMETERS Public iStandardFilterOnOff As Integer Public iSampleFilterOnOff As Integer Public iDifferenceFilterOnOff As Integer Public iRotationCorrectionOnOff As Integer Public iLocalCorrectionOnOff As Integer Public iStandardAOIx As Integer Public iStandardAOIy As Integer Public iStandardAOIdx As Integer Public iStandardAOIdy As Integer Public iSampleAOIx As Integer Public iSampleAOIy As Integer Public iSampleAOIdx As Integer Public iSampleAOIdy As Integer Public iRepeatHorizontal As Integer Public iRepeatVertical As Integer Public dSensitivity As Double Public iMergeWidth As Integer Public iMergeHeight As Integer Public iMinimumDifferenceArea As Integer Public iMaximumDifferenceArea As Integer End Structure在VB.NET中,System.Runtime.InteropServices.Marshal.sizeof()给出了88个字节.我希望,因为这些只是数值,这将起作用(我知道字符串可能会很痛苦).我没有外部函数的代码,但它声明如下:
Declare Function MNtvaParameters Lib "MNTva.dll" (ByRef pParameters As TVA_PARAMETERS) As Integer我猜这个结构大小不一样,所以DLL文件调用失败,但我没有错误,正如我所说,我没有代码来查看它.它返回零,如果成功则应该返回,但它显然没有实际效果.
我在Runtime.InteropServices.StructLayoutAttribute玩了一下,但如果这是答案,我无法确定正确的参数.