slavs
asked on
Converting VB6 to C#
Hi Experts,
I have a VB6 program that I am currently converting to C# and I am having issues interfacing to a particular method in an existing unmanaged dll.
All calls to the dll so far have worked perfectly, but this is the only method that passes a reference to a struct and is the only one I am having trouble with.
How would I write my dll import and call the method?
C++ dll Method declaration
VB Declaration of the dll
Type/Struct Definition
VB call to the dll
My best guess for the C# Code:
I have a VB6 program that I am currently converting to C# and I am having issues interfacing to a particular method in an existing unmanaged dll.
All calls to the dll so far have worked perfectly, but this is the only method that passes a reference to a struct and is the only one I am having trouble with.
How would I write my dll import and call the method?
C++ dll Method declaration
int _stdcall getVBArrayStrValues(LPSTR tagName, LPSTR itemName,
short firstElmNo, short lastElmNo, LPSAFEARRAY FAR * ppsaStringRead)
VB Declaration of the dll
Public Declare Function getVBArrayStrValues Lib "FILENAME.dll" _
(ByVal lpTagName As String, _
ByVal lpItemName As String, _
ByVal firstElmNo As Integer, _
ByVal lastElmNo As Integer, _
ByRef stringRead() As vbStringRead) As Integer
Type/Struct Definition
Type vbStringRead
readStatus As Integer
valueStr As String
End Type
VB call to the dll
ret = getVBArrayStrValues(tag, item, i1, i2, strRead())
My best guess for the C# Code:
ret = getVBArrayStrValues(tag, item, i1, i2, ref strRead);
public struct vbStringRead
{
public int readStatus;
public string valueStr;
}
[DllImport("FILENAME.dll")]
public static extern int getVBArrayStrValues(string lpTagName, string lpItemName, int firstElmNo, int lastElmNo, ref vbStringRead[] stringRead);
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I think I have a good idea of what I have to do now.