error 49 - bad dll calling convention 
Author Message
 error 49 - bad dll calling convention

I have code that I've used for months that includes calling GetUserName and
GetComputerName.
It suddenly won't work.

On a machine with Dr. Watson, it generates the frustrating, useless cryptic
access error.
On a non-Dr. Watson equipped machine, it generates error 49- Bad DLL
callling convention.
I've looked at the help for this and it hasn't suggested anything
enlightening.

IF I comment out the lines that call the declared api functions, it works
without an error, albeit uselessly - I guess this narrows it down.

I have no idea if this is  a clue or not:  I noticed that there are
duplicate entries in the API text viewer for both of these functions
(getusername and getcomputername) and none others.  I don't know how the api
text viewer creates its list.  If it is somehow smart enough to look in dlls
for functions or interfaces, perhaps I have an ambiguity problem of some
kind.  I'm only guessing of course.   This seems unlikely also because of
the fact that it no longer works on any machine.

I'd certainly appreciate any suggestions.

This is the code, called from an Access VBA standard module:

the declarations:

Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As Variant, nSize As Long) As Long

Public Declare Function GetComputerName Lib "kernel32" Alias
"GetComputerNameA" (ByVal lpBuffer As Variant, nSize As Long) As Long

where it's called:

    Dim stUser As Variant

    Dim stBuffer As Variant

    Dim lnSize As Long

    stBuffer = Space$(255)
    lnSize = Len(stBuffer)

    Call GetUserName(stBuffer, lnSize)
'<---------------------------------problem

    If lnSize > 0 Then
        stUser = Trim$(left$(stBuffer, lnSize))
    Else
        stUser = ""
    End If

    Dim stComputer As Variant

    stBuffer = Space$(255)
    lnSize = Len(stBuffer)

    Call GetComputerName(stBuffer, lnSize)
'<---------------------------------problem
    If lnSize > 0 Then
        stComputer = Trim$(left$(stBuffer, lnSize))
    Else
        stComputer = ""
    End If



Sat, 07 Jul 2001 03:00:00 GMT  
 error 49 - bad dll calling convention
Hi carlo:

Quote:
>Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
>(ByVal lpBuffer As Variant, nSize As Long) As Long

>Public Declare Function GetComputerName Lib "kernel32" Alias
>"GetComputerNameA" (ByVal lpBuffer As Variant, nSize As Long) As Long

Don't use Variants, use Strings.

Doug.



Sat, 07 Jul 2001 03:00:00 GMT  
 error 49 - bad dll calling convention
So, in spite of the fact that the declaration calls for a variant, it should
be a string only?
Thanks for responding.

Quote:

>Don't use Variants, use Strings.

>Doug.


Quote:
>Hi carlo:

>>Public Declare Function GetUserName Lib "advapi32.dll" Alias
"GetUserNameA"
>>(ByVal lpBuffer As Variant, nSize As Long) As Long

>>Public Declare Function GetComputerName Lib "kernel32" Alias
>>"GetComputerNameA" (ByVal lpBuffer As Variant, nSize As Long) As Long



Sun, 08 Jul 2001 03:00:00 GMT  
 error 49 - bad dll calling convention
Hi Carlo:

Quote:
>So, in spite of the fact that the declaration calls for a variant, it
should
>be a string only?

Where did you get the declaration from that you are using?  The declaration
I use (and which is also found in the api viewer) uses Strings, not
Variants.

I suspect the reason you are getting the error, is because the api function
is expecting a string and you are trying to pass a variant.

Try replacing "Variant" in your declaration with "String" (as I suggested
earlier) and see if that helps.

Doug.



Sun, 08 Jul 2001 03:00:00 GMT  
 error 49 - bad dll calling convention
If you declare the function with variant to pass a null pointer (a 0&) your
should declare it as Any not as Variant.

--
Eduardo Morcillo

http://www.geocities.com/SiliconValley/Foothills/9940/index_sp.html

Quote:

>Hi Carlo:

>>So, in spite of the fact that the declaration calls for a variant, it
>should
>>be a string only?

>Where did you get the declaration from that you are using?  The declaration
>I use (and which is also found in the api viewer) uses Strings, not
>Variants.

>I suspect the reason you are getting the error, is because the api function
>is expecting a string and you are trying to pass a variant.

>Try replacing "Variant" in your declaration with "String" (as I suggested
>earlier) and see if that helps.

>Doug.



Sun, 08 Jul 2001 03:00:00 GMT  
 error 49 - bad dll calling convention
Hi Eduardo:

Quote:
>If you declare the function with variant to pass a null pointer (a 0&) your
>should declare it as Any not as Variant.

Perhaps you missed the point of my last post.
The function expects a CString, or a Null, not a Variant.
If you have to pass a null, you can use vbNullstring.

Doug.



Sun, 08 Jul 2001 03:00:00 GMT  
 error 49 - bad dll calling convention
I was referring to the message that starts the discussion and was for any
var type (like RECT or POINTAPI). Your answer was right.

--
Eduardo Morcillo
e d a n m o +AEA- g e o c i t i e s . c o m
http://www.geocities.com/SiliconValley/Foothills/9940/index+AF8-sp.html
+AD4-Hi Eduardo:
+AD4-
+AD4APg-If you declare the function with variant to pass a null pointer (a 0+ACY-)
your
+AD4APg-should declare it as Any not as Variant.
+AD4-
+AD4-
+AD4-Perhaps you missed the point of my last post.
+AD4-The function expects a CString, or a Null, not a Variant.
+AD4-If you have to pass a null, you can use vbNullstring.
+AD4-
+AD4-Doug.
+AD4-
+AD4-
+AD4-



Mon, 09 Jul 2001 03:00:00 GMT  
 error 49 - bad dll calling convention
That fixed it.  Wish it was documented a little better for us API novices
using the text viewer.

Thanks for your help Douglas.



Mon, 09 Jul 2001 03:00:00 GMT  
 error 49 - bad dll calling convention
Hi carlo:

Quote:
>That fixed it.  Wish it was documented a little better for us API novices
>using the text viewer.

Dan Appleman has an excellent API reference:  www.desware.com  - Visual
Basic Programmer's Guide To The Win32 API

Doug.



Mon, 09 Jul 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Error 49: Bad Dll Calling convention

2. Help Re: error 49 Bad DLL calling convention

3. Error 49 -- Bad DLL Calling Convention

4. Run-time error '49': Bad DLL calling convention

5. Bad DLL calling convention (error 49)

6. Bad Calling Convention error 49 - due to calling a Sub in a .bas module

7. Possible answer to Err 49: Bad DLL calling convention

8. Possible answer to Err 49: Bad DLL calling convention

9. RunTime 49: Bad DLL Calling Convention

10. error 49 - Bad DLL callling convention

11. Help! Bad DLL Convention(49)

12. Access200 - Error 49: "Bad DLL calling..."

 

 
Powered by phpBB® Forum Software