Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_components thread: passing parameters to a DLL from ASP page


Message #1 by "Ashu Gupta" <ashu26@r...> on Thu, 22 Feb 2001 12:12:40
I've made a DLL called DBDrugsOperation which

contains the class clsDBOperation.

clsGetRecordset is a function in the class clsDBOperation.

The problem is, that when i try to pass parameters to 

this function, i get the following error:



Microsoft VBScript runtime error '800a000d' 

Type mismatch: 'clsGetRecordset' 



'The function declaration in the DLL is as follows:



Public Function clsGetRecordset(ByVal SQLQuery As String, _

                   Recordset As ADODB.Recordset, _

                  Optional ByVal Options As QUERYOPTIONS = QO_UseDefault, _

                  Optional ByVal UseShapeProvider As Boolean = False) _

                  As Boolean



'Purpose:           Function opens a connection using ADO

'                   and executes a query passed to it.

'                   This function returns records in a DISCONNECTED 

'                    recordset.



'Input Parameter:   Connect string which is a registered DSN,

'                   Query string to be executed,

'                   A recordset to return records in.

'Output Parameter:  Returns TRUE if the function succeeds





' Following is the code in the ASP page

' which is calling the function in our DLL called DBDrugsOperation





dim strSql as string

dim bolvar as boolean

dim objDBOperation 	' Object declaration of class clsdbOperation 



' DBDrugsOperation is the name of the DLL which

' contains the class clsDBOperation.

' Create an instance of clsDBOperation class to get the connection string 



set objDBOperation = server.CreateObject

("DBDrugsOperation.clsDBOperation") 



strSQL = cstr("SELECT * FROM EmergencyDrugRequest WHERE 1<>1") 

set rsDrugRequest=server.CreateObject("ADODB.Recordset") 

bolvar=objDBOperation.clsGetRecordset(strSQL,rsDrugRequest)







Message #2 by "Willy Vanthuyne" <willy@m...> on Thu, 22 Feb 2001 14:07:40 +0100
Hello,



Have you tried definiing the function as variant?

clsGetRecordset(ByVal SQLQuery As String, _

                   Recordset As ADODB.Recordset, _

                  Optional ByVal Options As QUERYOPTIONS = QO_UseDefault, _

                  Optional ByVal UseShapeProvider As Boolean = False) _

                  As Variant

'Type mismatch' seems to point in that dirextion

I hope this helps



Willy Vanthuyne



----- Oorspronkelijk bericht -----

Van: "Ashu Gupta" <ashu26@r...>

Aan: "ASP components" <asp_components@p...>

Verzonden: donderdag 22 februari 2001 12:12

Onderwerp: [asp_components] passing parameters to a DLL from ASP page





> I've made a DLL called DBDrugsOperation which

> contains the class clsDBOperation.

> clsGetRecordset is a function in the class clsDBOperation.

> The problem is, that when i try to pass parameters to

> this function, i get the following error:

>

> Microsoft VBScript runtime error '800a000d'

> Type mismatch: 'clsGetRecordset'

>

> 'The function declaration in the DLL is as follows:

>

> Public Function clsGetRecordset(ByVal SQLQuery As String, _

>                    Recordset As ADODB.Recordset, _

>                   Optional ByVal Options As QUERYOPTIONS = QO_UseDefault,

_

>                   Optional ByVal UseShapeProvider As Boolean = False) _

>                   As Boolean

>

> 'Purpose:           Function opens a connection using ADO

> '                   and executes a query passed to it.

> '                   This function returns records in a DISCONNECTED

> '                    recordset.

>

> 'Input Parameter:   Connect string which is a registered DSN,

> '                   Query string to be executed,

> '                   A recordset to return records in.

> 'Output Parameter:  Returns TRUE if the function succeeds

>

>

> ' Following is the code in the ASP page

> ' which is calling the function in our DLL called DBDrugsOperation

>

>

> dim strSql as string

> dim bolvar as boolean

> dim objDBOperation ' Object declaration of class clsdbOperation

>

> ' DBDrugsOperation is the name of the DLL which

> ' contains the class clsDBOperation.

> ' Create an instance of clsDBOperation class to get the connection string

>

> set objDBOperation = server.CreateObject

> ("DBDrugsOperation.clsDBOperation")

>

> strSQL = cstr("SELECT * FROM EmergencyDrugRequest WHERE 1<>1")

> set rsDrugRequest=server.CreateObject("ADODB.Recordset")

> bolvar=objDBOperation.clsGetRecordset(strSQL,rsDrugRequest)

>

>
Message #3 by "Ashu Gupta" <ashu26@r...> on Fri, 23 Feb 2001 05:38:09

I forgot to mention :



The DLL gives NO problem when it is being 

accessed from a VB Application.







> Hello,

> 

> Have you tried definiing the function as variant?

> clsGetRecordset(ByVal SQLQuery As String, _

>                    Recordset As ADODB.Recordset, _

>                   Optional ByVal Options As QUERYOPTIONS = 

QO_UseDefault, _

>                   Optional ByVal UseShapeProvider As Boolean = False) _

>                   As Variant

> 'Type mismatch' seems to point in that dirextion

> I hope this helps

> 

> Willy Vanthuyne

 

Message #4 by "Peter Lanoie" <planoie@e...> on Fri, 23 Feb 2001 10:06:17 -0500
I have had similar problems.  I kept getting a 'type mismatch' error when

trying to pass an object into a function when all declarations and datatypes

were correct (and it worked fine in native VB).  What I've found is that

it's due to the way VBScript works with passing arguments.



I just read some helpful information from the Wrox VBScript Programmer's

Reference (very good BTW, ISBN: 1861002777)



The section titled "Objects and the Variant data type" (page 168) talks

about datatypes and objects. Here are some highlights:



-The only data type in VBScript is the Variant

-Object's methods may be hav parameters passed by reference (ByRef) or by

value (ByVal)

-For a ByVal argument, VBScript will handle the conversion automatically

-For a ByRef argument, VBScript will NOT handle the conversion

automatically, and expects you to pass it the correct type:

	For a function: DoSomething(ByRef strSomeString as String)

	You must call as: DoSomething(Cstr(mystring))

-Most components written for scripting will have arguments passed ByVal or

be of type Variant (or both i suppose)



The way I got that component to work was by using this argument declaration:

ByRef object As Variant

I can't say that I ever had that problem with basic data types, but I see

that your function has a recordset for an argument.



Like another response suggested, maybe change the Function return datatype

to variant.  Also you could try calling the function with a string

conversion on the first argument.



Keep playing with the datatypes and eventually you'll find a combination

that will work.





-----Original Message-----

From: Ashu Gupta [mailto:ashu26@r...]

Sent: Friday, February 23, 2001 12:38 AM

To: ASP components

Subject: [asp_components] Re: passing parameters to a DLL from ASP page







I forgot to mention :



The DLL gives NO problem when it is being

accessed from a VB Application.







> Hello,

>

> Have you tried definiing the function as variant?

> clsGetRecordset(ByVal SQLQuery As String, _

>                    Recordset As ADODB.Recordset, _

>                   Optional ByVal Options As QUERYOPTIONS 

QO_UseDefault, _

>                   Optional ByVal UseShapeProvider As Boolean = False) _

>                   As Variant

> 'Type mismatch' seems to point in that dirextion

> I hope this helps

>

> Willy Vanthuyne

Message #5 by "Adrian Forbes" <adrian.forbes@n...> on Mon, 26 Feb 2001 18:25:22
> Public Function clsGetRecordset(ByVal SQLQuery As String, _

>                    Recordset As ADODB.Recordset, _

>                   Optional ByVal Options As QUERYOPTIONS = 

QO_UseDefault, _

>                   Optional ByVal UseShapeProvider As Boolean = False) _

>                   As Boolean



You omitted the ByVal from the Recordset param so it will default to 

ByRef.  You can only acces Variant's ByRef via ASP.  If Recordset is not 

an output param then add the ByVal.  If Recordset *is* an output param 

them make it a variant



Public Function clsGetRecordset(ByVal SQLQuery As String, _

                    ByVal Recordset As ADODB.Recordset, _





or



Public Function clsGetRecordset(ByVal SQLQuery As String, _

                    ByRef Recordset As variant, _


  Return to Index