Question Problems with functions. Specified Cast is not valid

eduardoquiroz

New member
Joined
Jun 17, 2010
Messages
1
Programming Experience
Beginner
Hello everyone.
I'm having a trouble with a function from a class and I need some help.
I've just 1 webpage and 1 vb file. In the vb file I have something like this:
VB.NET:
Public Class myclass
    Inherits System.Web.UI.Page
    <System.Runtime.InteropServices.DllImport("somelib.dll")> _
    Public Shared Function function1(ByVal par1 As System.IntPtr, _
                ByVal par2 As Integer) As Long
    End Function
End Class
And I have my web page with something like this:
VB.NET:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="myclass.vb" Inherits="myclass"  Debug="true"%>
<%
    Dim a As New myclass
    Dim DataIn
    Dim DataOut
    DataIn = "some text of in"
    DataOut = ""
    Try
        a.function1(DataIn, DataOut)
    Catch ex As Exception
        Response.Write("ERROR=" & ex.Message)
    End Try
    Response.Write("<br>TEST=" & DataOut)
 %>
And I'm having the following error :
"Specified cast is not valid"

What I'm doin' wrong?
Thanks in advance
 
Last edited by a moderator:
You've declared your function with two parameters of type IntPtr and Integer, then you call it and pass two Strings. You have to pass a function the type of data it expects.
 
Back
Top