none
Data type issue calling DLL function RRS feed

  • Question

  • My VBA environment is in a non-microsoft application.  My problem is with calling a DLL function from that VBA environment.  I think my issue is related to a fix-length string parameter in the DLL function.

    What would be the best forum for this question?

    Thanks

    Edit: modified title
    Tuesday, June 11, 2013 10:01 PM

All replies

  • I don't think you'll find a forum that specific.

    However, could you post here the declaration of the function that uses the DLL and how you are calling it? Also, what is the environment? WordPerfect, AutoCAD...? How are you calling the function and the error you're getting?


    Felipe Costa Gualberto - http://www.ambienteoffice.com.br

    Wednesday, June 12, 2013 12:56 AM
  • Thanks for the reply!  The environment is GEFanuc's Proficy iFIX Workspace.

    Would it make more sense for me to reproduce the issue in Excel and then post in the Excel VBA forum?  

    Here is my declaration and calling code:

    Private Declare Sub GetPasswordPolicy Lib "altusgina.dll" Alias "WlxGetPasswordPolicyRequirements" 
    (ByVal szDC As String, ByVal iLocale As Long, ByVal szUser As String, ByVal szPolicy As String)
    
    Sub Test1()
        Dim sRules As String
        
        sRules = String(2048, 0)
        Call GetPasswordPolicy("DomainName", 1033, "UserName", sRules)
        
    End Sub

    The call to GetPasswordPolicy generates this error:

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

    The last parameter in the declaration is a fixed-length string.  From VB.NET the call works fine with the last parameter declared as StringBuilder.

    I've tried using Variant, Object, String array and byte array but I always get the error above or a type mismatch.  If I don't initialize sRules in the code above then it crashes.

    Thanks!



    • Edited by Bollocks68 Wednesday, June 12, 2013 2:22 PM
    Wednesday, June 12, 2013 2:15 PM
  • I have no idea how a StringBuilder object should be called by an API in VBA.

    Just curiosity: the line

    sRules = String(2048, 0)

    How about trying this?

    sRules = String(2048, Chr(0))


    Felipe Costa Gualberto - http://www.ambienteoffice.com.br

    Thursday, June 13, 2013 3:18 AM
  • You might try fixing the string length.

    Dim sRules As String * 2048

    


    Cheers,

    Andy
    www.andypope.info

    Thursday, June 13, 2013 8:53 AM
  • Thanks for the suggestions.  I tried each and both together but I still get "Bad DLL calling convention." 
    Thursday, June 13, 2013 12:26 PM