CreateEnhMetafile returns NULL

CreateEnhMetafile returns NULL

Post by Jean-Marc Talloe » Wed, 30 Jun 1999 04:00:00



For some reason, my calls to Crea*hMetafile seem to be NULL, but when
querying GetLastError returns always 0?

(I use a NULL hRefDC handle)

Jean-Marc Talloen

 
 
 

CreateEnhMetafile returns NULL

Post by Jim Deutc » Thu, 01 Jul 1999 04:00:00


Careful!  NULL is not "NULL" in VB: it's "ByVal 0&".

Jim Deutch
MS Dev MVP


Quote:>For some reason, my calls to Crea*hMetafile seem to be NULL, but when
>querying GetLastError returns always 0?

>(I use a NULL hRefDC handle)

>Jean-Marc Talloen


 
 
 

CreateEnhMetafile returns NULL

Post by Stephen Leban » Thu, 01 Jul 1999 04:00:00


Hi Jean-Marc,
here's a SNIP from some code in  a project of mine. You can find the
full source code on my Web page. It creates Enhanced Metafiles on the
fly.

SNIP
 '**FROM MICROSOFT KNOWLEDGE BASE
    Dim sMMRect As RECTL
    Dim iWidthMM As Long, iHeightMM As Long
    Dim iWidthPels As Long, iHeightPels As Long

    iWidthMM = apiGetDeviceCaps(hDC, HORZSIZE)
    iHeightMM = apiGetDeviceCaps(hDC, VERTSIZE)
    iWidthPels = apiGetDeviceCaps(hDC, HORZRES)
    iHeightPels = apiGetDeviceCaps(hDC, VERTRES)

    sMMRect.Left = (.Left * iWidthMM * 100) / iWidthPels
    sMMRect.Top = (.Top * iHeightMM * 100) / iHeightPels
    sMMRect.Right = (.Right * iWidthMM * 100) / iWidthPels
    sMMRect.Bottom = (.Bottom * iHeightMM * 100) / iHeightPels

End With

    'OK let's create the enhanced Metafile
    'If you need to also create a disk file use this line
    'hdcMeta = apiCrea*hMetaFile(hDC, "SLemf.emf", sMMRect,
vbNullString)
    hdcMeta = apiCrea*hMetaFile(hDC, 0&, sMMRect, vbNullString)

HTH

Stephen Lebans

http://www.veryComputer.com/~slebans/


Quote:>For some reason, my calls to Crea*hMetafile seem to be NULL, but
when
>querying GetLastError returns always 0?

>(I use a NULL hRefDC handle)

>Jean-Marc Talloen

 
 
 

CreateEnhMetafile returns NULL

Post by Jean-Marc Talloe » Sat, 03 Jul 1999 04:00:00


Thanks, but I already know that...

 (I speak VB and C++ at the same time, I mean in the same project).

JM


Quote:>Careful!  NULL is not "NULL" in VB: it's "ByVal 0&".

>Jim Deutch
>MS Dev MVP

 
 
 

CreateEnhMetafile returns NULL

Post by Jean-Marc Talloe » Sat, 03 Jul 1999 04:00:00


Hallo,

Since it is a bit of a problem to grab to context if I havn't specified any,
I will show you the code that is offending and describe more precisely when
the error occurs.

Context:

I have written a component (ActiveX DLL, Apartment Threaded, VB6 SP2) which
contains code that creates a metafile. It receives the dimensions, the
reference DC, a filename and an optional comment as parameters (as you will
see in the code).

With the using code, I do not pass a references hDC in, so that
Crea*hMetafile relies on the display device (by default). Passing a
filename or not doesn't change a thing. Neither does the comment stuff.

When running the project in the IDE (both the ActiveX project and the main
project are loaded) then no error occurs at all: it simply works fine.

But when I compile the project, my call to Crea*hMetafile returns NULL
(sorry, I mean 0&) , this will be catched an finally an Err is raised in the
call to RaiseApiError (which retrieves the message description from the
passed in error code). But the error raised is: Err.Number := 0,
Description:= The operation completed successfully; which implies that no
error has been set by the failing call in Crea*hMetafile.

Code:

Friend Sub Init(ByVal hRefDC As Long, _
            ByVal Width As Long, ByVal Height As Long, _
            ByVal Filename As String, _
            ByVal Application As String, _
            ByVal Description As String)

    Dim R As RECT, Comment As String

    m_Recording = True

    m_Extent.cx = Width
    m_Extent.cy = Height
    m_Origin.Y = Height
    SetRect R, 0, 0, Width, Height

    If Application <> vbNullString Or Description <> vbNullString Then
        Comment = Application & Chr$(0) & Description & Chr$(0) & Chr$(0)
    Else
        Comment = vbNullString
    End If

    m_hDC = Crea*hMetaFile(hRefDC, Filename, R, Comment)
    If m_hDC = 0 Then
        m_Recording = False
        RaiseApiError GetLastError
    End If

    m_hMF = 0

End Sub

If you might be able to track this down, please let me know.

PS: Should I have created a new thread here?

 
 
 

1. Viewkit menuItem->baseWidget returns NULL

I'm not sure why baseWidget() is returning NULL. It should build the
menu and return the widget if necessary. But you can get what you want
by:

1) Calling VkMenu::useWorkProcs(FALSE); before you create your windows.
This disables the delayed build of menus, so the widget will exist right
away, possibly at the cost (small) of some startup time.

2) Update to 6.2. The latest viewkit already supports what I think you
are doing. (Showing help text as the user moves over widgets).

Incidently, I'd use arm and disarm callbacks to detect the user entering
and leaving an item rather than event handlers. That way, gadgets will
work fine.

Doug

2. Avoid Infotips with PSP Browser

3. glxChooseVisual returns NULL

4. Indy Video keying and effects

5. glGetString() always returns (null)

6. FS Sealed Adobe Publishing Collection for Windows

7. wglAllocateMemoryNV() returns NULL if priority=0.5

8. POVRay and Envelop...

9. glGetError returns GL_INVALID_OPERATION after wglMakeCurrent NULL

10. gl_vendor returns NULL instead of the vendor name

11. glGetString returns NULL

12. MAX export: (IPhyVertexExport *)GetVertexInterface(iVertex) ALWAYS returns NULL

13. createdibitmap intermittently returning null...