API Conversion 16 bit to 32 bit 
Author Message
 API Conversion 16 bit to 32 bit

Converting from Access 2.0 to Access 97 is relatively smooth, but I have
one stumbling block.  

I have a number of 16 bit API calls. Most convert into the 32 bit calls,
but one declare is baffling me:

Declare Funciton GetTextExtent Lib "GDI" (By Val hdc%, By Val lpString
As String, By Val nCount%) As Long

the only 32 bit functions that I have found are GetTextExtentExPoint Lib

but it does not work -- any suggestions or pointers would be much
appreciated.

Martin Streeter



Fri, 15 Oct 1999 03:00:00 GMT  
 API Conversion 16 bit to 32 bit

: I have a number of 16 bit API calls. Most convert into the 32 bit
: calls, but one declare is baffling me:
: Declare Funciton GetTextExtent Lib "GDI" (By Val hdc%, By Val
: lpString As String, By Val nCount%) As Long
: the only 32 bit functions that I have found are GetTextExtentExPoint
: but it does not work
:...............................

Hi Martin,

I think you'll find that GetTextExtentPoint is the one you need.
Here's a sample that should get you going ... assuming you have been
able to create the hdc in 32-bit beforehand.

Type API_SIZE
    lngWidth As Long
    lngHeight As Long
 End Type

Declare Function GetTextExtentPoint _
        Lib "gdi32" _
        Alias "GetTextExtentPointA" _
        (ByVal hdc As Long, _
        ByVal lpszString As String, _
        ByVal cbString As Long, _
        lpSize As SIZE) As Long

Dim typSize as API_SIZE
Dim lngret as long , lnghdc as long
Dim strText as string
strText = "How big is this"
lngRet = GetTextExtentPoint(lnghdc, strText, Len(strText), typSize)

-- Chris Bell --



Fri, 15 Oct 1999 03:00:00 GMT  
 API Conversion 16 bit to 32 bit

It seems you are very knowledgeable about API calls. I have a problem
with GETOPENFILENAME.

I used the Access 2.0 OpenCommDlg function that the Access help
desk people distributed for 2.0. Now that I am converting to 95, I
copied all the declares, types, etc. and modified everything according
to the article from MS Knowledge Base "How to convert 16-bit API to
32-bit"

I can display the box, change directories, select a file and written
on the file box but I can't filter by file type and I cannot capture
the filename.

I will appreciate a much-needed support from you! Thanks.

Fres  

Quote:


> : I have a number of 16 bit API calls. Most convert into the 32 bit
> : calls, but one declare is baffling me:
> : Declare Funciton GetTextExtent Lib "GDI" (By Val hdc%, By Val
> : lpString As String, By Val nCount%) As Long
> : the only 32 bit functions that I have found are GetTextExtentExPoint
> : but it does not work
> :...............................

> Hi Martin,

> I think you'll find that GetTextExtentPoint is the one you need.
> Here's a sample that should get you going ... assuming you have been
> able to create the hdc in 32-bit beforehand.

> Type API_SIZE
>     lngWidth As Long
>     lngHeight As Long
>  End Type

> Declare Function GetTextExtentPoint _
>         Lib "gdi32" _
>         Alias "GetTextExtentPointA" _
>         (ByVal hdc As Long, _
>         ByVal lpszString As String, _
>         ByVal cbString As Long, _
>         lpSize As SIZE) As Long

> Dim typSize as API_SIZE
> Dim lngret as long , lnghdc as long
> Dim strText as string
> strText = "How big is this"
> lngRet = GetTextExtentPoint(lnghdc, strText, Len(strText), typSize)

> -- Chris Bell --



Sun, 17 Oct 1999 03:00:00 GMT  
 API Conversion 16 bit to 32 bit


: I have a problem with GETOPENFILENAME.
: I can display the box, change directories, select a file and written

: on the file box but I can't filter by file type and I cannot capture

: the filename.
:...............................

Hi Fres,

I'll have a look at it if you post the pertinent declares and calls.
Otherwise I'm just guessing.

-- Chris Bell --



Mon, 18 Oct 1999 03:00:00 GMT  
 API Conversion 16 bit to 32 bit

So many people, including myself a couple of weeks ago, ask for this!  I
don't know why MS doesn't post the solution.  Paste this code into a
module.  All the parameters are optional.  There is a parameter for
"filterindex" (=1, 2 or whatever, depending on whether you want the first,
second, ect ext. to be your filter.), but the DefaultExt is easier to use.
The function returns the full file and path.  Good luck!

Option Compare Database
Option Explicit
'
'Function adapted from Microsoft Access 95 How-To by Getz and Litwin
'Chapter 4.8
'
Type tagOPENFILENAME
     lStructSize As Long
     hWndOwner As Long
     hInstance As Long
     strFilter As String
     strCustomFilter As String
     nMaxCustFilter As Long
     NFilterIndex As Long
     strFile As String
     nMaxFile As Long
     strFileTitle As String
     nMaxFileTitle As Long
     strInitialDir As String
     strTitle As String
     Flags As Long
     nFileOffset As Integer
     nFileExtension As Integer
     strDefExt As String
     lCustData As Long
     lpfnHook As Long
     lpTemplateName As String
End Type

Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" Alias
"GetOpenFileNameA" (ofn As tagOPENFILENAME) As Boolean
Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" Alias
"GetSaveFileNameA" (ofn As tagOPENFILENAME) As Boolean

Global Const ahtOFN_READONLY = &H1
Global Const ahtOFN_OVERWRITEPROMPT = &H2
Global Const ahtOFN_HIDEREADONLY = &H4
Global Const ahtOFN_NOCHANGEDIR = &H8
Global Const ahtOFN_SHOWHELP = &H10
' You won't use these.
'Global Const ahtOFN_ENABLEHOOK = &H20
'Global Const ahtOFN_ENABLETEMPLATE = &H40
'Global Const ahtOFN_ENABLETEMPLATEHANDLE = &H80
Global Const ahtOFN_NOVALIDATE = &H100
Global Const ahtOFN_ALLOWMULTISELECT = &H200
Global Const ahtOFN_EXTENSIONDIFFERENT = &H400
Global Const ahtOFN_PATHMUSTEXIST = &H800
Global Const ahtOFN_FILEMUSTEXIST = &H1000
Global Const ahtOFN_CREATEPROMPT = &H2000
Global Const ahtOFN_SHAREAWARE = &H4000
Global Const ahtOFN_NOREADONLYRETURN = &H8000
Global Const ahtOFN_NOTESTFILECREATE = &H10000
Global Const ahtOFN_NONETWORKBUTTON = &H20000
Global Const ahtOFN_NOLONGNAMES = &H40000
' New for Windows 95
Global Const ahtOFN_EXPLORER = &H80000
Global Const ahtOFN_NODEREFERENCELINKS = &H100000
Global Const ahtOFN_LONGNAMES = &H200000

Function OpenCommDlg(Optional ByVal InitialDir As Variant, _
 Optional ByVal FilterIndex As Variant, Optional ByVal DefaultExt As
Variant, _
 Optional ByVal filename As Variant, _
 Optional ByVal DialogTitle As Variant, _
 Optional ByVal Hwnd As Variant, _
 Optional ByVal OpenFile As Variant) As Variant

    'USAGE:
    'OpenCommDlg(InitialDir:="C:\",
DefaultExt:="*.DOC",DialogTitle:="Select your document!")
    '
    ' This is the entry point you'll use to call the common
    ' file open/save dialog. The parameters are listed
    ' below, and all are optional.
    '
    ' In:
    '    InitialDir: the directory in which to first look
    '
    '    FilterIndex: 1-based integer indicating which filter
    '            set to use, by default (1 if unspecified).
    '
    '    DefaultExt: Extension to use if the user doesn't enter one.
    '    You can user either FilterIndex or DefaultExt.  The DefaultExt
sets the FilterIndex in the function.
    '    FileName: Default value for the file name text box.
    '    DialogTitle: Title for the dialog.
    '    hWnd: parent window handle
    '    OpenFile: Boolean(True=Open File/False=Save As)
    ' Out:
    '    Return Value: Either Null or the selected filename

    Dim ofn As tagOPENFILENAME
    Dim strFileName As String
    Dim strFileTitle, Message As String
    Dim fResult As Boolean
    Dim Flags As Variant

    '-------------------------------------------------------------------
    Dim lngResult As Long

    '-------------------------------------------------------------------
    'Set flags for various features.  To set a flag, set its IF statement
to true.
    'Flags: one or more of the ahtOFN_* constants, OR'd together.
    '
    Dim lngFlags As Long
    lngFlags = 0
    'Prompt before overwriting?
    If False Then lngFlags = lngFlags Or ahtOFN_OVERWRITEPROMPT
    'Hide the read-only check box?
    If True Then lngFlags = lngFlags Or ahtOFN_HIDEREADONLY
    'Show the Help button?
    If False Then lngFlags = lngFlags Or ahtOFN_SHOWHELP
    'Skip filename validation?
    If False Then lngFlags = lngFlags Or ahtOFN_NOVALIDATE
    'Allow multiple selections?
    If False Then lngFlags = lngFlags Or ahtOFN_ALLOWMULTISELECT
    'Prompt if specified path doesn't exist?
    If False Then lngFlags = lngFlags Or ahtOFN_PATHMUSTEXIST
    'Prompt if specified file doesn't exist for opening?
    If False Then lngFlags = lngFlags Or ahtOFN_FILEMUSTEXIST
    'Prompt if necessary to create new file?
    If False Then lngFlags = lngFlags Or ahtOFN_CREATEPROMPT
    'Use Explorer look (when options would override this?)
    If False Then lngFlags = lngFlags Or ahtOFN_EXPLORER
    'Show link names, rather than linked reference for links?
    If False Then lngFlags = lngFlags Or ahtOFN_NODEREFERENCELINKS
    'Hide the network button?
    If False Then lngFlags = lngFlags Or ahtOFN_NONETWORKBUTTON
    '
    'End of flag setting block
    '-------------------------------------------------------------------
    '
    '-------------------------------------------------------------------
    'Block to define the "File of Type" filter for showing filenames.
    'Add or comment out as you wish.  They will be displayed in the Common
Dialog Box in the
    'order shown here.  The Filter Index variable specifies which filter
will be displayed
    'first, as a default.
    '
    Dim Filter As String
    Filter = Filter & "Word Files (*.doc)" & vbNullChar & "*.DOC" &
vbNullChar
    Filter = Filter & "Access Files (*.mda, *.mdb)" & vbNullChar &
"*.MDA;*.MDB" & vbNullChar
    Filter = Filter & "dBASE Files (*.dbf)" & vbNullChar & "*.DBF" &
vbNullChar
    Filter = Filter & "Text Files (*.txt)" & vbNullChar & "*.TXT" &
vbNullChar
    Filter = Filter & "EXE Files (*.exe)" & vbNullChar & "*.EXE" &
vbNullChar
    Filter = Filter & "All Files (*.*)" & vbNullChar & "*.*" & vbNullChar
    'The Filter Index sets which filter will be used as the default.  You
do not need it, but
    'it's here if you do.

    If Not IsMissing(DefaultExt) Then
        If DefaultExt = "*.DOC" Then
        FilterIndex = 1
        ElseIf DefaultExt = "*.MDB" Then
        FilterIndex = 2
        ElseIf DefaultExt = "*.DBF" Then
        FilterIndex = 3
        ElseIf DefaultExt = "*.TXT" Then
        FilterIndex = 4
        ElseIf DefaultExt = "*.EXE" Then
        FilterIndex = 5
        Else
        FilterIndex = 6
        End If
    End If
    '
    'End of block to define filter.
    '-------------------------------------------------------------------
    '
    '-------------------------------------------------------------------
    'Initialize any missing parameters that were not passed by the call, or
initialized in this function.
    '
    If IsMissing(InitialDir) Then InitialDir = CurDir
    If IsMissing(Filter) Then Filter = ""
    If IsMissing(FilterIndex) Then FilterIndex = 1
    If IsMissing(lngFlags) Then Flags = 0&
    If IsMissing(DefaultExt) Then DefaultExt = ""
    If IsMissing(filename) Then filename = ""
    If IsMissing(DialogTitle) Then DialogTitle = ""
    If IsMissing(Hwnd) Then Hwnd = Application.hWndAccessApp
    If IsMissing(OpenFile) Then OpenFile = True
    '
    'End if parameter initialization block
    '-------------------------------------------------------------------
    '
    ' Allocate string space for the returned strings.
    strFileName = Left(filename & String(256, 0), 256)
    strFileTitle = String(256, 0)
    '
    ' Set up the data structure before you call the function
    With ofn
        .lStructSize = Len(ofn)
        .hWndOwner = Hwnd
        .strFilter = Filter
        .NFilterIndex = FilterIndex
        .strFile = strFileName
        .nMaxFile = Len(strFileName)
        .strFileTitle = strFileTitle
        .nMaxFileTitle = Len(strFileTitle)
        .strTitle = DialogTitle
        .Flags = Flags
        .strDefExt = DefaultExt
        .strInitialDir = InitialDir

        ' Didn't think most people would want to deal with
        ' these options.
        .hInstance = 0
        .strCustomFilter = ""
        .nMaxCustFilter = 0
        .lpfnHook = 0
    End With

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

    If OpenFile Then
        fResult = aht_apiGetOpenFileName(ofn)
    Else
        fResult = aht_apiGetSaveFileName(ofn)
    End If
    '
    ' The function call filled in the strFileTitle member
    ' of the structure. You'll have to write special code
    ' to retrieve that if you're interested.
    '
    If fResult Then
        ' You might care to check the Flags member of the
        ' structure to get information about the chosen file.
        ' In this example, if you bothered to pass in a
        ' value for Flags, we'll fill it in with the outgoing
        ' Flags value.
        If Not IsMissing(Flags) Then Flags = ofn.Flags

        'Trim the NULLS off the file mame.
        Dim intPos As Integer
        intPos = InStr(ofn.strFile, vbNullChar)
        If intPos > 0 Then
            OpenCommDlg = Left(ofn.strFile, intPos - 1)
        Else
            OpenCommDlg = ofn.strFile
        End If

    Else
        OpenCommDlg = Null 'NULL caused problems when the calling function
declared a String type.
        'OpenCommDlg = ""
    End If

If Len(OpenCommDlg) > 0 Or Not IsNull(OpenCommDlg) Then
'Message$ = "The file you chose was " + ofn.strFile
'MsgBox Message$
Else
Message$ = "No file was selected"
MsgBox Message$
End If

End Function

--
Mike Freeland

Remove the "ROUNDFILE" in the return address.
Sorry for the inconvenience.

Martin Streeter ...

read more »



Mon, 18 Oct 1999 03:00:00 GMT  
 API Conversion 16 bit to 32 bit

Hi Mike,



Quote:
> So many people, including myself a couple of weeks ago, ask for this!  I
> don't know why MS doesn't post the solution.  

You have the reason right some lines after that:

Quote:
> '
> 'Function adapted from Microsoft Access 95 How-To by Getz and Litwin
> 'Chapter 4.8

I think Ken Getz had posted it, as a sample, almost two years ago, in
another BBS, but myself, I would have some restrictions to repost it. Just
as a remark, be carefull to know that a code is really "public" before
posting it. I don't want to stop your enthousiasm in sharing your
discovery, but admit that if every one begin to paste code in this
newsgroup, without enough wrights to do it, it just won't be funny to have
the FBI closing this newsgroup because there are to many complaints about
"piracy". Note that I don't work for MS neither I am an official voice of
anykind, an MVP is just that, another human being,

Regards,
Michel Walsh, Access MVP



Fri, 22 Oct 1999 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. 16-bit to 32-bit conversion problem

2. 16 bit and 32 bit platform conversion

3. VB 4.0 conversion from 32 bit to 16 bit

4. 16-bit to 32-bit DLL conversion

5. 16 bit to 32 bit conversion

6. VB4: 32-bit to 16-bit conversion

7. VB 4 16 bit to 32 bit conversion

8. 16-bit to 32-bit conversion

9. 32 bit equivalent of 16 bit API call GetModuleUsage

10. Need some 16 bit and 32 bit API assistance

11. 16 bit API calls in VB 3 supported in 32 bit VB 4.0

 

 
Powered by phpBB® Forum Software