Groups | Blog | Home
all groups > inetserver asp components > august 2003 >

inetserver asp components : How to wrap DLL to make it usable in ASP


mguerreiro NO[at]SPAM lanefurniture.com
8/27/2003 12:14:09 AM
I am experiencing a problem that is common for hundreds of ASP
programmers and hopefully we'll be able to solve it here for
everybody.

General Problem: Type mismatch when you pass parameters from ASP to a
VB Component.
Specific Problem: I am using a DLL (3rd party) in VB and I use the
same DLL in ASP on all its properties and methods except one (the most
important one) because this specific method (X.getTextVar()) has 1
argument that returns a pointer to a BSTR type instead of a Variant,
so it occurred to me that I could make a wrapper ActiveX Component for
this DLL in which I would change the problematic method to return
Variants instead of BSTR. The original DLL was written in VC++ and
compiled to be used in VB programs. Is it possible to do what I want
to do? How do I go about doing it? I've never created a DLL wrapper
before.

The proposed solutions should address the sequence of steps on making
the wrapper and modifying the X.getTextVar (Pointer to BSTR) method to
make it get a string and return a Variant. In VBA we can just do "Dim
MyVar As String" and then do X.getTextVar(MyVar). At the end of this
instruction "MyVar" contains a value passed by reference from the
Object "X", but this does not happen in ASP. ASP generates a type
mismatch...simply because the method wants a String and all we can
give it is a Variant. Doing X.getTextVar(CStr(MyVar)) does not end
with a mismatch, but it does not return anything either because the
address that contains the value is never passed out to us, it resides
somewhere in the HEAP.

Documented in Microsoft Knowledge Base articles: 197957, 244012, and
197956.

Description: These knowledge articles talk about this problem as if
the majority of us (ASP programmers) create our own DLL's. The problem
is that there are many 3rd party DLLs that we can successfully use in
Visual Basic for Applications, but that will fail miserably in ASP
just because of the Passing by Reference problem depicted here. On top
of this, Microsoft only shows how to solve the problem if you have the
source code for the DLL, which is not the case when we use 3rd party
DLLs. However, in theory we should be able to create a wrapper that
solves the problem.

This is a hard one, but maybe you can shed some light to hundreds of
us. Thanks for contributing.

Drebin
8/27/2003 1:07:28 PM
Can't you get that value by using the "set" keyword:

Set bstrRet = x.getTextVar()

instead of

bstrRet = x.getTextVar()

I'm nearly certain that part of COM compliance is that binary strings are
REALLY variant binary strings (like a VT_BSTR) - and if memory serves, that
is going to come back as a byte arry (I *think*?) hth

[quoted text, click to view]

AddThis Social Bookmark Button