argument not optional in a dll error. Does anyone know why me code is generating this error

I am using the following code to call functions from a dll

Private Declare Function CreateFile Lib "SynMF.dll" ( _
                                ByVal createfilename As String, _
                                ByVal magic As Long, _
                                ByVal appname As String, _
                                ByVal username As String, _
                                ByVal usercomments As String, _
                                ByVal sourcepath As String, _
                                ByVal sourcename As String, _
                                ByVal firstsourcenumber As Long, _
                                ByVal lastsourcenumber As Long, _
                                ByVal sourcetype As String, _
                                ByVal originx As Double, _
                                ByVal originy As Double, _
                                ByVal originz As Double, _
                                ByVal reversex As Boolean, _
                                ByVal reversey As Boolean, _
                                ByVal reversez As Boolean, _
                                ByVal factorx As Double, _
                                ByVal factory As Double, _
                                ByVal unitsxy As Long, _
                                ByVal factorz As Double, _
                                ByVal unitsz As Long, _
                                ByVal unitsdisplay As Long) As Boolean

When I include the following call

Dim createfilename As String
    createfilename = FileNameBox.Text
    Dim magic As Long
    magic = 1
    Dim appname As String
    appname = App.Title & " v" & App.Major & "." & App.Minor & "." & App.Revision
    Dim username As String
    username = UserNameBox.Text
    Dim usercomments As String
    usercomments = UserCommentsBox.Text
    Dim sourcepath As String
    sourcepath = SourcePathBox.Text
    Dim sourcename As String
    sourcename = SourceNameBox.Text
    Dim firstsourcenumber As Long
    firstsourcenumber = FirstSourceBox.Text
    Dim lastsourcenumber As Long
    lastsourcenumber = LastSourceBox.Text
    Dim sourcetype As String
    sourcetype = FileTypeCombo.Text
    Dim originx As Double
    originx = XOriginBox.Text
    Dim originy As Double
    originy = YOriginBox.Text
    Dim originz As Double
    originz = ZOriginBox.Text
    Dim reversex As Boolean
    reversex = XReverseCheck.Value
    Dim reversey As Boolean
    reversey = YReverseCheck.Value
    Dim reversez As Boolean
    reversez = ZReverseCheck.Value
    Dim factorx As Double
    factorx = XYFactorBox.Text
    Dim factory As Double
    factory = XYFactorBox.Text
    Dim unitsxy As Long
    unitsxy = 3
    Dim factorz As Double
    factorz = ZFactorBox.Text
    Dim unitsz As Long
    unitsz = 3
    Dim unitsdisplay As Long
    unitsdisplay = 2
   Dim result As Boolean
'result = CreateFile(createfilename, magic, appname, username, usercomments, sourcepath, sourcename, firstsourcenumber, lastsourcenumber, sourcetype, originx, originy, originz, reversex, reversey, factorx, factory, unitsxy, factorz, unitsz, unitsdisplay)
     result = CreateFile(createfilename, magic, appname, username, usercomments, sourcepath, sourcename, firstsourcenumber, lastsourcenumber, sourcetype, originx, originy, originz, reversex, reversey, factorx, factory, unitsxy, factorz, unitsz, unitsdisplay)
    If result = True Then
        MsgBox "File created"
        MsgBox "Create FAILED"
    End If

I have tried several configurations with no siccuess anyone any iadea why?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

your missing reversez in the call
eneateAuthor Commented:

Thanks for the feedback, but I now get the error bad dll calling convention, any idea why?

Maybe try:

result = CreateFile(ByVal createfilename, ByVal magic, ByVal appname, ByVal username, ByVal usercomments, ByVal sourcepath, ByVal sourcename, ByVal firstsourcenumber, ByVal lastsourcenumber, ByVal sourcetype, ByVal originx, ByVal originy, ByVal originz, ByVal reversex, ByVal reversey, ByVal reversez, ByVal factorx, ByVal factory, ByVal unitsxy, ByVal factorz, ByVal unitsz, ByVal unitsdisplay)
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

eneateAuthor Commented:
I still get the same error
When you get the error, can you click debug to see what line is being highlighted? Is it the call to CreateFile?  I can't test any further because I don't have "SynMF.dll" on my system.
If you compile to an exe do you still get the same error?;en-us;Q153586
eneateAuthor Commented:

Sorry, been away, you are right when I compile and run the program I don't get the error, I guess it must be a vb 6 thing?
From the above link:

It is not possible to directly call a C function in a DLL if that function uses the _cdecl calling convention. This is because Visual Basic uses the _stdcall calling convention for calling functions. This is a problem because if _cdecl is used, the calling function is responsible for cleaning up the stack. However, if _stdcall is used, the called function is responsible for cleaning up the stack.

NOTE: An .EXE file created in Visual Basic will allow you to call a DLL function that has been declared with the _cdecl calling convention without an error. It is only when you try to call such a function when running a program from the Visual Basic IDE, that Visual Basic generates the following error:

Run-time Error '49':
Bad DLL Calling Convention

The fact that the EXE version allows you to call such functions has been confirmed to be a bug by Microsoft. You should not rely on this behavior as this might change in future versions of Visual Basic.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eneateAuthor Commented:
Thanks for the feedback at least I know where the problem is.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.