How to write declaration myself to use Comdlg32.dll?

I have a case I need to use Save As dialog (Microsoft Common Dialog -- comdlg32.dll) allowing user to choose a folder from an application (Docbasic, which is similar to VB but not VB). Please note:

1) I have to use comdlg32.dll, not comdlg32.ocx (ActiveX control). I can't use ActiveX control in Docbasic.

2) I need a handle when using the dll Save As dialog -- I need to pass filename to the filename field in the dialog. User doesn't need to type in filename when the Save As dialog pops up. And I also need to catch the folder path that user selected. So only launching the dialog without having a handle would not work.

3) VB has a predefined declaration for using this dll dialog for VB applications in a file called Win32api.txt. The declaration is like this:

-- begin

Private Type OPENFILENAME
        lStructSize As Long
        hwndOwner As Long
        hInstance As Long
        lpstrFilter As String
        lpstrCustomFilter As String
        nMaxCustFilter As Long
        nFilterIndex As Long
        lpstrFile As String
        nMaxFile As Long
        lpstrFileTitle As String
        nMaxFileTitle As Long
        lpstrInitialDir As String
        lpstrTitle As String
        flags As Long
        nFileOffset As Integer
        nFileExtension As Integer
        lpstrDefExt As String
        lCustData As Long
        lpfnHook As Long
        lpTemplateName As String
End Type

Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long

-- end

Then I can call the function from a VB application. it works fine. Now my question is: how can I do the similar thing myself in another language?

Thank you very much!
yzmaoAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
KDivadConnect With a Mentor Commented:
Oops! Remove the GetOpenFileName line from that sub. The API-Guide used it to force an error so that the select case would show something.
0
 
Dave_GreeneCommented:
What language?
0
 
yzmaoAuthor Commented:
Docbasic. A language for Documentum (a knowledge management software).
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
KDivadCommented:
Does it support APIs? What format is an API in (post one!)?
0
 
Richie_SimonettiIT OperationsCommented:
Interesting... give us more info.
0
 
PaulHewsCommented:
You will have to check the documentation for Docbasic to see if it supports calls to DLLs (not Active X DLLs, but the function based kind.)
0
 
Richie_SimonettiIT OperationsCommented:
"I have a case I need to use Save As dialog (Microsoft Common Dialog -- comdlg32.dll) allowing user to
choose a folder from an application "
did you try with browseforfolders stuff, it is pretty easy.
0
 
yzmaoAuthor Commented:
Hi,

Thanks for everyone!

Does it support APIs?

  -- Yes. The declaration is similar to(if not exactly as) VB. But I do have a problem here: I found that the structure name OPENFILENAME is a reserved word in Docbasic. So I can't use it to declare the structure I need. Do I hit a dead end?

Docbasic documentation:

  -- Of course I checked all documentation. Unfortunately, nothing I could find for further instruction. It is obvious that I have to do something meself -- with the help from your guys.

 "did you try with browseforfolders stuff, it is pretty easy" -- what is this? Would you please give more info?

Note: Docbasic is similar to VB (with less functionality, of course). So approaches in VB (not ActiveX) to Windows API might work.

Thanks a lot!
0
 
KDivadCommented:
<<... the structure name OPENFILENAME is a reserved word ...>>

So change it:

Private Type VBOPENFILENAME

Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename
As VBOPENFILENAME) As Long
0
 
yzmaoAuthor Commented:
I did -- I mean I used another name for the structure. The Docbasic program runs, no error -- the return value was also correct, but the Save As dialog was not launched. I didn't know what was wrong.

So you mean the name of the structure doesn't matter?
0
 
KDivadCommented:
That's correct. The structure name is irrelevant, as are the names of parameters and the API itself (though Alias and Lib must be left alone!). It doesn't even exist in the compiled exe (unless you are exporting the structure), it's just an easy way to refer to memory locations when you are writing source and is converted to memory pointers in the final exe. In fact, this will work just fine:

Private Type Yeah_Whatever

Private Declare Function DoThatThing Lib "comdlg32.dll" Alias "GetSaveFileNameA" (Alright As Yeah_Whatever) As Long


There is an API you can use after the call to see if there was an error:

Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long

An easy way to use it is contained in AllAPI's API-Guide (I made a few minor changes, but nothing functional):

==================
Const CDERR_DIALOGFAILURE = &HFFFF
Const CDERR_FINDRESFAILURE = &H6
Const CDERR_GENERALCODES = &H0
Const CDERR_INITIALIZATION = &H2
Const CDERR_LOADRESFAILURE = &H7
Const CDERR_LOADSTRFAILURE = &H5
Const CDERR_LOCKRESFAILURE = &H8
Const CDERR_MEMALLOCFAILURE = &H9
Const CDERR_MEMLOCKFAILURE = &HA
Const CDERR_NOHINSTANCE = &H4
Const CDERR_NOHOOK = &HB
Const CDERR_REGISTERMSGFAIL = &HC
Const CDERR_NOTEMPLATE = &H3
Const CDERR_STRUCTSIZE = &H1
Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
Private Sub ShowError()

    GetOpenFileName ByVal 0&
    Select Case CommDlgExtendedError
        Case CDERR_DIALOGFAILURE
            MsgBox "The dialog box could not be created."
        Case CDERR_FINDRESFAILURE
            MsgBox "The common dialog box function failed to find a specified resource."
        Case CDERR_INITIALIZATION
            MsgBox "The common dialog box function failed during initialization."
        Case CDERR_LOADRESFAILURE
            MsgBox "The common dialog box function failed to load a specified resource."
        Case CDERR_LOADSTRFAILURE
            MsgBox "The common dialog box function failed to load a specified string."
        Case CDERR_LOCKRESFAILURE
            MsgBox "The common dialog box function failed to lock a specified resource."
        Case CDERR_MEMALLOCFAILURE
            MsgBox "The common dialog box function was unable to allocate memory for internal structures."
        Case CDERR_MEMLOCKFAILURE
            MsgBox "The common dialog box function was unable to lock the memory associated with a handle."
        Case CDERR_NOHINSTANCE
            MsgBox "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a corresponding instance handle."
        Case CDERR_NOHOOK
            MsgBox "The ENABLEHOOK flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a pointer to a corresponding hook procedure."
        Case CDERR_REGISTERMSGFAIL
            MsgBox "The RegisterWindowMessage function returned an error code when it was called by the common dialog box function."
        Case CDERR_NOTEMPLATE
            MsgBox "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a corresponding template."
        Case CDERR_STRUCTSIZE
            MsgBox "The lStructSize member of the initialization structure for the corresponding common dialog box is invalid."
        Case Else
            MsgBox "Undefined error ..."
    End Select

End Sub
================

This might tell you what went wrong with your call and give you a chance to fix your code.

Good luck!
0
 
Richie_SimonettiIT OperationsCommented:
were you declaring that variable of type:VBOPENFILENAME?
if so, were you declaraing API with this newname as parameter type?
If so, were you pass that var to openfilename function?
0
 
yzmaoAuthor Commented:
Thanks for everyone!
0
 
KDivadCommented:
You're welcome!

I assume you got it working, then?
0
 
yzmaoAuthor Commented:
Yes, I have tested in VB, as you said the name of the structure is irrelevant. But I still have problem in Docbasic, that's my own problem now -- I mean the software problem.

You are pretty good.
0
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.

All Courses

From novice to tech pro — start learning today.