Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems with API

12 views
Skip to first unread message

Jörg Brokamp

unread,
Sep 29, 1997, 3:00:00 AM9/29/97
to

Hi, I扉e got Problems with the API-Function GetOpenFileName. The script
comes from Q96114. But no dialog box opened. I used it under Office97
with Win95.

Is there anybody out there, to help?


'-------------------------------------------------------
' Global Declaration Section
'-------------------------------------------------------
Option Compare Database
Option Explicit

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

Declare Function GetOpenFileName% Lib "COMDLG32.DLL" Alias
"GetOpenFileNameA" (OPENFILENAME As tagOPENFILENAME)

Declare Function GetSaveFileName% Lib "COMDLG32.DLL" Alias
"GetOpenFileNameA" (OPENFILENAME As tagOPENFILENAME)

Declare Function lstrcpy& Lib "Kernel32" Alias "lstrcpyA" (ByVal
lpDestString As Any, ByVal lpSourceString As Any)

Declare Function CommDlgExtendedError& Lib "COMDLG32.DLL" ()

Dim OPENFILENAME As tagOPENFILENAME

Global Const OFN_READONLY = &H1
Global Const OFN_OVERWRITEPROMPT = &H2
Global Const OFN_HIDEREADONLY = &H4
Global Const OFN_NOCHANGEDIR = &H8
Global Const OFN_SHOWHELP = &H10
Global Const OFN_ENABLEHOOK = &H20
Global Const OFN_ENABLETEMPLATE = &H40
Global Const OFN_ENABLETEMPLATEHANDLE = &H80
Global Const OFN_NOVALIDATE = &H100
Global Const OFN_ALLOWMULTISELECT = &H200
Global Const OFN_EXTENSIONDIFFERENT = &H400
Global Const OFN_PATHMUSTEXIST = &H800
Global Const OFN_FILEMUSTEXIST = &H1000
Global Const OFN_CREATEPROMPT = &H2000
Global Const OFN_SHAREAWARE = &H4000
Global Const OFN_NOREADONLYRETURN = &H8000
Global Const OFN_NOTESTFILECREATE = &H10000

Global Const OFN_SHAREFALLTHROUGH = 2
Global Const OFN_SHARENOWARN = 1
Global Const OFN_SHAREWARN = 0

'-------------------------------------------------------
' Open Common Dialog Function
'-------------------------------------------------------
Function OpenCommDlg()
Dim Message$, Filter$, FileName$, FileTitle$, DefExt$
Dim Title$, szCurDir$, APIResults%
Dim Err_Message$

'*Define the filter string and allocate space in the "c" string
Filter$ = "*.TXT" & Chr$(0)

'* Allocate string space for the returned strings.
FileName$ = Chr$(0) & Space$(255) & Chr$(0)
FileTitle$ = Space$(255) & Chr$(0)

'* Give the dialog a caption title.
Title$ = "My File Open Dialog" & Chr$(0)

'* If the user does not specify an extension, append TXT.
DefExt$ = "TXT" & Chr$(0)

'* Set up the default directory
szCurDir$ = CurDir$ & Chr$(0)

'* Set up the data structure before you call the GetOpenFileName

OPENFILENAME.lStructSize = Len(OPENFILENAME)

'* Set up the window handle
OPENFILENAME.hwndOwner = Screen.ActiveForm.Hwnd

OPENFILENAME.lpstrFilter = lstrcpy(Filter$, Filter$)
OPENFILENAME.nFilterIndex = 1
OPENFILENAME.lpstrFile = lstrcpy(FileName$, FileName$)
OPENFILENAME.nMaxFile = Len(FileName$)
OPENFILENAME.lpstrFileTitle = lstrcpy(FileTitle$, FileTitle$)
OPENFILENAME.nMaxFileTitle = Len(FileTitle$)
OPENFILENAME.lpstrTitle = lstrcpy(Title$, Title$)
OPENFILENAME.Flags = OFN_FILEMUSTEXIST Or OFN_READONLY
OPENFILENAME.lpstrDefExt = lstrcpy(DefExt$, DefExt$)
OPENFILENAME.hInstance = 0
OPENFILENAME.lpstrCustomFilter = 0
OPENFILENAME.nMaxCustFilter = 0
OPENFILENAME.lpstrInitialDir = lstrcpy(szCurDir$, szCurDir$)
OPENFILENAME.nFileOffset = 0
OPENFILENAME.nFileExtension = 0
OPENFILENAME.lCustData = 0
OPENFILENAME.lpfnHook = 0
OPENFILENAME.lpTemplateName = 0

'* This will pass the desired data structure to the Windows API,
'* which in turn uses it to display the Open Dialog form.

APIResults% = GetOpenFileName(OPENFILENAME)

If APIResults% <> 0 Then

'* Note that FileName$ will have an embedded Chr$(0) at the
'* end. You may wish to strip this character from the string.

FileName$ = Left$(FileName$, InStr(FileName$, Chr$(0)) - 1)

Message$ = "The file you chose was " + FileName$
Else
Message$ = "No file was selected"
End If

MsgBox Message$

Err_Message$ = CommDlgExtendedError()

MsgBox Err_Message$

End Function


Thank you


Steve Arbaugh

unread,
Sep 30, 1997, 3:00:00 AM9/30/97
to

Jörg:

The code you used was basically 16 bit code and structures with replaced 32
bit function declarations. To resolve your problem you need to make the
following changes:

In the UDT tagOpenFileName, change all elements which are ints to longs
except, nFileOffset As Integer
and nFileExtension As Integer. Change all elements which are lpstrs to
strings, rather than longs. Then when you copy strings into the UDT
variables, skip using lstrcpy, and just set them as strings as in
OPENFILENAME.lpstrTitle = "My Dlg Title"

Should solve the problem for you.

HTH
--
Steve Arbaugh
ATTAC Consulting Group
web: http://ourworld.compuserve.com/homepages/attac-cg/acgsoft.htm
Reply Address adjusted to control spams remove leading ~ and NoSpm from
address
Send Replys to: ~75323...@NoSpm.Compuserve.com

Jörg Brokamp <jbro...@aol.com> wrote in article
<342FA210...@aol.com>...
> Hi, I´ve got Problems with the API-Function GetOpenFileName. The script

> OPENFILENAME.lpstrTitle = lstrcpy(Title$, Title$)


0 new messages