Passing parameters to a DLL
-
Wednesday, May 09, 2012 7:04 PM
I am trying to convert some old VB6 code to VS2008 VB.Net
VB6 code
Public itemcount as Long
Public CHandles() As Long
Public SHandles() As Long
Public rerrors() As Long
... code to determine how many items
itemcount=32
ReDim SHandles(1 To itemcount)
ReDim rerrors(1 To itemcount)
ReDim CHandles(1 To itemcount)
ReDim Str(1 To itemcount)
'Now call the dll.
group.OPCItems.AddItems(itemcount, Str, SHandles, CHandles, rerrors)
The call in vb6 above works but seemed to require arrays dimensioned as 1 to itemcount.
Now port to VB.Net 2008
Public CHandles() As Integer
Public SHandles() As Integer
Public rerrors() As Integer
Public itemcount as integer
... code to determine how many items
itemcount=32
ReDim SHandles(itemcount)
ReDim CHandles(itemcount)
ReDim rerrors(itemcount)
'Now call the dll.
'str(0...) = text strings
group.OPCItems.AddItems(itemcount, Str, SHandles, CHandles, rerrors)
error returned is
"Unable to cast object of type 'System.Int32[*]' to type 'System.Int32[]'."
"When casting from a number, the value must be a number less than infinity"
Make sure the source type is convertible to the destination type.
If I look at the definition in the object browser, here is what I see.
AddItems(Integer,ByRef Sytem.Array,ByRef Sytem.Array,ByRef Sytem.Array)
The DLL is the same as the one used in vb6 and other calls to that dll work.
The DLL is opcdaauto.dll
Any help would be appreciated.Thanks
Tom Ryan
All Replies
-
Thursday, May 10, 2012 7:12 AMModerator
Hi lkytmr1957,
Welcome to the MSDN forum.
First of all, you need to check the version of your DLL file. As far as I know, some version of this DLL (such as 2.0) is only provided for VB6. So check whether this DLL is support for .Net framework or just select another dll instead.
Hope this helps.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us
- Marked As Answer by Mark Liu-lxfModerator Tuesday, May 22, 2012 7:48 AM
- Unmarked As Answer by Mark Liu-lxfModerator Tuesday, May 22, 2012 8:57 AM
-
Friday, May 11, 2012 4:09 PM
Mark,
Thanks. I am not sure how to tell which version of DLL I am using but it shipped with RSLinx this year. It has a 2007 date on it. All the other dll features seem to work.
Isn't there a way to look at the definition of the function and determine how to pass in the parameters?
AddItems(Integer,ByRef Sytem.Array,ByRef Sytem.Array,ByRef Sytem.Array)
Also I thought that as long as your parameter stack was right, the dll should respond to the request regardless of which system you called it from.
Tom
-
Monday, May 14, 2012 9:21 AMModerator
Hi lkymr1957,
The dll is a third party product. So I have no other information about it.
As the parameter (array) in it is 1 based array which is different in the VB.Net (0 based). So I’m afraid that the dll is not suitable for using at VB.Net. That’s why I suggest you to connect the website of this dll and find whether it has the version for .Net freamwork.
Hope this helps.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us
-
Tuesday, May 22, 2012 7:48 AMModerator
Hi lkymr1957,
Any update about this issue?
Sorry for any inconvenience and have a nice day.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us
- Edited by Mark Liu-lxfModerator Tuesday, May 22, 2012 8:58 AM

