Need help with respect to CDialog-based display of dialog in Excelthrough xll

  • Thread starter ThirstyForKnowledge
  • Start date
T

ThirstyForKnowledge

Can anyone out there tell me how to display a CDialog-based dialog
control from within XLL. I have managed to cratee an MFC extension
XLL (i.e., originally dll but tweaked to become xll). I have
different NON-VISUAL functions and commands that can be used from
within excel spreadsheet and excel menus, but I cannoy manage to
create a command that will display an MFC CDialog -based dialog
control.

I would really appreciate if there are any experts who could give me
direction what do i need to do.

Thank you in advance
 
J

Joel

Why did you change DLL to XLL? You should be calling a DLL even if you are
calling it within the XLL.

Below is some code that may help. You need to declare the functions before
you use them as shown below.


Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'-------------------------------------------------------------
Function GetFolder(Optional ByVal Name As String = _
"Select a folder.") As String
'-------------------------------------------------------------
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long

bInfo.pidlRoot = 0& 'Root folder = Desktop

bInfo.lpszTitle = Name

bInfo.ulFlags = &H1 'Type of directory to Return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog

'Parse the result
path = Space$(512)

GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If

End Function

Sub Folder()
Dim c As Range, rng As Range
Set rng = Range("H1:H10")
For Each c In rng
c.Value = GetFolder
Next c
End Sub
 
T

ThirstyForKnowledge

Why did you change DLL to XLL? You should be calling a DLL even if you are
calling it within the XLL.

Below is some code that may help.  You need to declare the functions before
you use them as shown below.

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
    Alias "SHGetPathFromIDListA" _
   (ByVal pidl As Long, _
    ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
    Alias "SHBrowseForFolderA" _
   (lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
  hOwner As Long
  pidlRoot As Long
  pszDisplayName As String
  lpszTitle As String
  ulFlags As Long
  lpfn As Long
  lParam As Long
  iImage As Long
End Type

    '-------------------------------------------------------------
    Function GetFolder(Optional ByVal Name As String = _
                "Select a folder.") As String
    '-------------------------------------------------------------
    Dim bInfo As BROWSEINFO
    Dim path As String
    Dim oDialog As Long

        bInfo.pidlRoot = 0&                 'Root folder = Desktop

        bInfo.lpszTitle = Name

        bInfo.ulFlags = &H1                 'Type of directory to Return
        oDialog = SHBrowseForFolder(bInfo)  'display the dialog

        'Parse the result
        path = Space$(512)

        GetFolder = ""
        If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
            GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
        End If

    End Function

Sub Folder()
Dim c As Range, rng As Range
Set rng = Range("H1:H10")
For Each c In rng
c.Value = GetFolder
Next c
End Sub

Hi Joel,

I'm sorry for not having been clear as to what I really need to find
out. I really need to solve that problem above with C++, not
VBA ...but thanks for your drive to help others and thanks for taking
the time to reply.
 
J

Joel

The solution for C++ is very similar to Visual Basic. You find plenty of
info on the web and at microsoft.com in you look a CDIALOG Win32 C++.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top