EDIT: Having got this to work under 32-bit, I am now trying to get it to work on 64-bit. I got the source code for the DLL, and both the DLL and the application are compiled for 64-bit. I get an access violation every time. Here is the DLL code (C ++ in Visual Studio 2005 ):
#pragma pack( push, 2 )
Please note that installing the package on 2. I tried to install it on 2 in the application, and it does not work. I tried other values, and I even tried values ββthat were not the same. I tried explicitly using 4 as an integer size and 8 as a double size. But I would suggest (with limited knowledge) that if both package sizes are the same, they should work.
At this point, I suspect how the function is being called. Its first parameter is a pointer to an array of these structures. The application passes in the first element of the ByRef array, which, I think, does this. But having a bad array pointer would explain the symptoms. Here is the function definition in the DLL.
int WINAPI MNtvaAnalyzeVB (TVA_RESULTS *pResults, int iMaxCount)
My boss suggested this might be a big / little endian problem, but it seems unlikely if they are both compiled in the same environment.
What should I do?
End of editing β>
I am converting a Visual Basic 6.0 application to VB.NET. I have a couple of structures that are transferred to external DLL files. This does not work, and I feel it due to the incorrect transfer of structures.
Here's the original structure:
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
If I do LenB for a variable of this type in Visual Basic 6.0, I get 84 bytes. (NB: I'm not sure if this is the right way to determine its size.)
I tried converting it to 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
In VB.NET, System.Runtime.InteropServices.Marshal.sizeof () gives 88 bytes. I was hoping these were just numerical values ββthat would work (I know that strings can be pain). I do not have code for an external function, but it was declared as follows:
Declare Function MNtvaParameters Lib "MNTva.dll" (ByRef pParameters As TVA_PARAMETERS) As Integer
I assume that this structure is not the same size, so the DLL file call fails, but I do not get an error, and, as I said, I do not have code to view it. It returns zero, as it should if it is successful, but it clearly has no effect.
I played a little with Runtime.InteropServices.StructLayoutAttribute , but if that is the answer, I cannot determine the correct parameters.
I have another structure similar to this one, but it is so similar. I guess I can fix it, I can fix another.