Home All Groups Group Topic Archive Search About

extending Type structure and Run-time error '49': Bad DLL calling convention

Author
4 Jun 2005 3:46 AM
Jack
I am at the loss to explain the follwing:

Type LINECALLSTATUS
    dwTotalSize As Long
    dwNeededSize As Long
    dwUsedSize As Long

    dwCallState As Long
    dwCallStateMode As Long
    dwCallPrivilege As Long
    dwCallFeatures As Long

    dwDevSpecificSize As Long
    dwDevSpecificOffset As Long
End Type
Public Const LINECALLSTATUS_FIXEDSIZE = 36

Public Sub rlineCheckCallStatus(ByVal Line As Long)
    Dim b As LINECALLSTATUS
    b.dwTotalSize = LINECALLSTATUS_FIXEDSIZE + 2048
            rtn = lineGetCallStatus(hNewCall(Line), b)
End Sub

When I call that sub from another sub I have this error:
Run-time error '49':
Bad DLL calling convention

But, when I extend the Type LINECALLSTATUS by my own code:
mem As String * 2048 ' ADDED BY Jack
like shown below  I do not have that error
Type LINECALLSTATUS
    dwTotalSize As Long
    dwNeededSize As Long
    dwUsedSize As Long

    dwCallState As Long
    dwCallStateMode As Long
    dwCallPrivilege As Long
    dwCallFeatures As Long

    dwDevSpecificSize As Long
    dwDevSpecificOffset As Long
    mem As String * 2048 ' ADDED BY Jack
End Type

and change sub like this:
Public Sub rlineCheckCallStatus(ByVal Line As Long)
    Dim b As LINECALLSTATUS
    b.dwTotalSize = len(b)
            rtn = lineGetCallStatus(hNewCall(Line), b)
End Sub

I checked. In both cases value of b.dwTotalSize is the same. So why that
error?
I need to know why I am having that error in the first case. It is not
permanent error. After retrying several times (Debug and Run) vbasic let me
finish that call after some time.
Your thoughts deeply appreciated.
Jack

Author
4 Jun 2005 11:00 PM
Jim Edgar
Show quote Hide quote
"Jack" <replyto@newsgroup> wrote in message
news:%23uLKLgLaFHA.2736@TK2MSFTNGP12.phx.gbl...
> I am at the loss to explain the follwing:
>
> Type LINECALLSTATUS
>     dwTotalSize As Long
>     dwNeededSize As Long
>     dwUsedSize As Long
>
>     dwCallState As Long
>     dwCallStateMode As Long
>     dwCallPrivilege As Long
>     dwCallFeatures As Long
>
>     dwDevSpecificSize As Long
>     dwDevSpecificOffset As Long
> End Type
> Public Const LINECALLSTATUS_FIXEDSIZE = 36
>
> Public Sub rlineCheckCallStatus(ByVal Line As Long)
>     Dim b As LINECALLSTATUS
>     b.dwTotalSize = LINECALLSTATUS_FIXEDSIZE + 2048
>             rtn = lineGetCallStatus(hNewCall(Line), b)
> End Sub
>

I haven't used lineGetCallStatus() but I do see a couple of items that may
be causing you some trouble.  First, since the rtn variable is not declared
in the function then you may not have Option Explicit set which forces
variable declarations.  Second, dwTotalSize "probably" is the size of the
UDT.  Since the UDT LINECALLSTATUS is declared with 9 Long datatypes then
the total size is 36.  For some reason you add 2048 to the total size which
might explain why it blows up.  In your second example you (or Jack) include
a sized string variable to pad out the type then use Len(b) to get the size
which should be the same as LINECALLSTATUS_FIXEDSIZE + 2048.  Try something
like this:

Option Explicit
Type LINECALLSTATUS
    dwTotalSize As Long
    dwNeededSize As Long
    dwUsedSize As Long

    dwCallState As Long
    dwCallStateMode As Long
    dwCallPrivilege As Long
    dwCallFeatures As Long

    dwDevSpecificSize As Long
    dwDevSpecificOffset As Long
End Type

Public Function rlineCheckCallStatus(ByVal Line As Long) As Long
    Dim b As LINECALLSTATUS
    b.dwTotalSize = Len(b)
            rlineCheckCallStatus = lineGetCallStatus(hNewCall(Line), b)
End Function

Run it without adding:
    mem As String(2048)
to the UDT and see what happens.

Who knows, it might work,

Jim Edgar
Author
5 Jun 2005 4:22 PM
Jack
Thanks for your reply, but as I said I have already working solution.
What I need is help in understanding mechanism of  extending UDT structure.
Why it works when I add the line:
    mem As String * 2048 ' ADDED BY Jack
to the structure
but why it does not, when I extend reserved space for the structure by
adding extra 2048 bytes (arbirtrary number).
b.dwTotalSize = LINECALLSTATUS_FIXEDSIZE + 2048

BTW, my name is Jack, Options are set to be Explicit and rtn is declared
properly (as Long)
Jack

Show quoteHide quote
"Jim Edgar @cox.net>" <djedgar<removethis> wrote in message
news:%23xql2kVaFHA.2128@TK2MSFTNGP14.phx.gbl...
>
> "Jack" <replyto@newsgroup> wrote in message
> news:%23uLKLgLaFHA.2736@TK2MSFTNGP12.phx.gbl...
>> I am at the loss to explain the follwing:
>>
>> Type LINECALLSTATUS
>>     dwTotalSize As Long
>>     dwNeededSize As Long
>>     dwUsedSize As Long
>>
>>     dwCallState As Long
>>     dwCallStateMode As Long
>>     dwCallPrivilege As Long
>>     dwCallFeatures As Long
>>
>>     dwDevSpecificSize As Long
>>     dwDevSpecificOffset As Long
>> End Type
>> Public Const LINECALLSTATUS_FIXEDSIZE = 36
>>
>> Public Sub rlineCheckCallStatus(ByVal Line As Long)
>>     Dim b As LINECALLSTATUS
>>     b.dwTotalSize = LINECALLSTATUS_FIXEDSIZE + 2048
>>             rtn = lineGetCallStatus(hNewCall(Line), b)
>> End Sub
>>
>
> I haven't used lineGetCallStatus() but I do see a couple of items that may
> be causing you some trouble.  First, since the rtn variable is not
> declared
> in the function then you may not have Option Explicit set which forces
> variable declarations.  Second, dwTotalSize "probably" is the size of the
> UDT.  Since the UDT LINECALLSTATUS is declared with 9 Long datatypes then
> the total size is 36.  For some reason you add 2048 to the total size
> which
> might explain why it blows up.  In your second example you (or Jack)
> include
> a sized string variable to pad out the type then use Len(b) to get the
> size
> which should be the same as LINECALLSTATUS_FIXEDSIZE + 2048.  Try
> something
> like this:
>
> Option Explicit
> Type LINECALLSTATUS
>    dwTotalSize As Long
>    dwNeededSize As Long
>    dwUsedSize As Long
>
>    dwCallState As Long
>    dwCallStateMode As Long
>    dwCallPrivilege As Long
>    dwCallFeatures As Long
>
>    dwDevSpecificSize As Long
>    dwDevSpecificOffset As Long
> End Type
>
> Public Function rlineCheckCallStatus(ByVal Line As Long) As Long
>    Dim b As LINECALLSTATUS
>    b.dwTotalSize = Len(b)
>            rlineCheckCallStatus = lineGetCallStatus(hNewCall(Line), b)
> End Function
>
> Run it without adding:
>    mem As String(2048)
> to the UDT and see what happens.
>
> Who knows, it might work,
>
> Jim Edgar
>
>
Author
6 Jun 2005 8:13 AM
Bruno Köller
> What I need is help in understanding mechanism of  extending UDT
> structure.
> Why it works when I add the line:
>    mem As String * 2048 ' ADDED BY Jack
> to the structure
> but why it does not, when I extend reserved space for the structure by
> adding extra 2048 bytes (arbirtrary number).
> b.dwTotalSize = LINECALLSTATUS_FIXEDSIZE + 2048

the UDT member's name dwTotalSize is nothing more than a promise how to
interpret its content
Author
6 Jun 2005 10:47 AM
David Youngblood
"Jack" <replyto@newsgroup> wrote...
> Thanks for your reply, but as I said I have already working solution.
> What I need is help in understanding mechanism of  extending UDT structure.
> Why it works when I add the line:
>     mem As String * 2048 ' ADDED BY Jack
> to the structure
> but why it does not, when I extend reserved space for the structure by
> adding extra 2048 bytes (arbirtrary number).
> b.dwTotalSize = LINECALLSTATUS_FIXEDSIZE + 2048

How would vb and windows know to not use those 2048 bytes for something else?
Memory used by your program needs to be reserved. I assume that
lineGetCallStatus returns a structure + *extra* data. Two general ways to handle
this are, 1) Declare an array of structures large enough to hold both the
structure and extra data. The first element contains the structure and the
remaining elements are simply storage space for the extra data.  2) Use a byte
array
lagre enough to hold the structure and data. I have used the former but not the
latter.

An example from a defualt printer class,
      '* Allocate enough space for the Printer Info structure
      ReDim ppi2(dwNeeded \ SIZEOFPRINTER_INFO_2)

David


Show quoteHide quote
> BTW, my name is Jack, Options are set to be Explicit and rtn is declared
> properly (as Long)
> Jack
>
> "Jim Edgar @cox.net>" <djedgar<removethis> wrote in message
> news:%23xql2kVaFHA.2128@TK2MSFTNGP14.phx.gbl...
> >
> > "Jack" <replyto@newsgroup> wrote in message
> > news:%23uLKLgLaFHA.2736@TK2MSFTNGP12.phx.gbl...
> >> I am at the loss to explain the follwing:
> >>
> >> Type LINECALLSTATUS
> >>     dwTotalSize As Long
> >>     dwNeededSize As Long
> >>     dwUsedSize As Long
> >>
> >>     dwCallState As Long
> >>     dwCallStateMode As Long
> >>     dwCallPrivilege As Long
> >>     dwCallFeatures As Long
> >>
> >>     dwDevSpecificSize As Long
> >>     dwDevSpecificOffset As Long
> >> End Type
> >> Public Const LINECALLSTATUS_FIXEDSIZE = 36
> >>
> >> Public Sub rlineCheckCallStatus(ByVal Line As Long)
> >>     Dim b As LINECALLSTATUS
> >>     b.dwTotalSize = LINECALLSTATUS_FIXEDSIZE + 2048
> >>             rtn = lineGetCallStatus(hNewCall(Line), b)
> >> End Sub
> >>
> >
> > I haven't used lineGetCallStatus() but I do see a couple of items that may
> > be causing you some trouble.  First, since the rtn variable is not
> > declared
> > in the function then you may not have Option Explicit set which forces
> > variable declarations.  Second, dwTotalSize "probably" is the size of the
> > UDT.  Since the UDT LINECALLSTATUS is declared with 9 Long datatypes then
> > the total size is 36.  For some reason you add 2048 to the total size
> > which
> > might explain why it blows up.  In your second example you (or Jack)
> > include
> > a sized string variable to pad out the type then use Len(b) to get the
> > size
> > which should be the same as LINECALLSTATUS_FIXEDSIZE + 2048.  Try
> > something
> > like this:
> >
> > Option Explicit
> > Type LINECALLSTATUS
> >    dwTotalSize As Long
> >    dwNeededSize As Long
> >    dwUsedSize As Long
> >
> >    dwCallState As Long
> >    dwCallStateMode As Long
> >    dwCallPrivilege As Long
> >    dwCallFeatures As Long
> >
> >    dwDevSpecificSize As Long
> >    dwDevSpecificOffset As Long
> > End Type
> >
> > Public Function rlineCheckCallStatus(ByVal Line As Long) As Long
> >    Dim b As LINECALLSTATUS
> >    b.dwTotalSize = Len(b)
> >            rlineCheckCallStatus = lineGetCallStatus(hNewCall(Line), b)
> > End Function
> >
> > Run it without adding:
> >    mem As String(2048)
> > to the UDT and see what happens.
> >
> > Who knows, it might work,
> >
> > Jim Edgar
> >
> >
>
>