Link to home
Start Free TrialLog in
Avatar of rossryan
rossryan

asked on

Bitmaps & errors

struct SapphireData
{
Bitmap SapphireSwap;
};


SapphireData->SapphireSwap = Bitmap::FromHBITMAP(hBmp, CPalette::operator HPALETTE);

I need to copy a bitmap into a struct for shared memory. Why do I get a lot of errors when using this statement?

code beforehand:

hBmp = NULL;

    {
        HDC hDC = GetDC(hWnd);
        hBmp = CreateCompatibleBitmap(hDC, rect.right - rect.left, rect.bottom - rect.top);
        ReleaseDC(hWnd, hDC);
    }
      hOld = SelectObject(hDCMem, hBmp);
Avatar of caner_elci
caner_elci

Can you paste those errors here?
Avatar of rossryan

ASKER

------ Build started: Project: hook, Configuration: Debug Win32 ------

Compiling...
hookpaint.cpp
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusImaging.h(67) : error C2501: 'MIDL_INTERFACE' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusImaging.h(67) : error C2440: 'initializing' : cannot convert from 'const char [37]' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusImaging.h(67) : error C2146: syntax error : missing ';' before identifier 'IImageBytes'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusImaging.h(67) : error C2470: 'IImageBytes' : looks like a function definition, but there is no formal parameter list; skipping apparent body
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusImaging.h(67) : error C2059: syntax error : 'public'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusImaging.h(246) : error C2146: syntax error : missing ';' before identifier 'id'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusImaging.h(246) : error C2501: 'Gdiplus::PropertyItem::PROPID' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusImaging.h(246) : error C2501: 'Gdiplus::PropertyItem::id' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(384) : error C2143: syntax error : missing ')' before '*'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(384) : error C2143: syntax error : missing ';' before '*'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(384) : error C2460: 'Gdiplus::Image::IStream' : uses 'Gdiplus::Image', which is being defined
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(372) : see declaration of 'Gdiplus::Image'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(384) : error C2501: 'Gdiplus::Image::stream' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(384) : error C2146: syntax error : missing ';' before identifier 'useEmbeddedColorManagement'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(384) : error C2501: 'Gdiplus::Image::BOOL' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(384) : error C2059: syntax error : ')'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(384) : error C2864: 'useEmbeddedColorManagement' : only const static integral data members can be initialized inside a class or struct
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(384) : error C2501: 'Gdiplus::Image::useEmbeddedColorManagement' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(395) : error C2061: syntax error : identifier 'IStream'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(405) : error C2061: syntax error : identifier 'IStream'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(443) : error C2061: syntax error : identifier 'PROPID'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(444) : error C2061: syntax error : identifier 'PROPID'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(445) : error C2061: syntax error : identifier 'PROPID'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(453) : error C2061: syntax error : identifier 'PROPID'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(499) : error C2143: syntax error : missing ')' before '*'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(499) : error C2143: syntax error : missing ';' before '*'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(499) : error C2460: 'Gdiplus::Bitmap::IStream' : uses 'Gdiplus::Bitmap', which is being defined
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(488) : see declaration of 'Gdiplus::Bitmap'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(499) : error C2501: 'Gdiplus::Bitmap::stream' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(499) : error C2146: syntax error : missing ';' before identifier 'useEmbeddedColorManagement'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(499) : error C2501: 'Gdiplus::Bitmap::BOOL' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(499) : error C2059: syntax error : ')'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(499) : error C2864: 'useEmbeddedColorManagement' : only const static integral data members can be initialized inside a class or struct
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(499) : error C2501: 'Gdiplus::Bitmap::useEmbeddedColorManagement' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusHeaders.h(510) : error C2061: syntax error : identifier 'IStream'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1133) : error C2065: 'IStream' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1133) : error C2065: 'stream' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1133) : error C2065: 'image' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1133) : error C2275: 'Gdiplus::GpImage' : illegal use of this type as an expression
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusGpStubs.h(61) : see declaration of 'Gdiplus::GpImage'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1133) : warning C4229: anachronism used : modifiers on data are ignored
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1133) : error C2078: too many initializers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1139) : error C3861: 'IStream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1139) : error C3861: 'stream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1139) : error C2275: 'Gdiplus::GpImage' : illegal use of this type as an expression
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusGpStubs.h(61) : see declaration of 'Gdiplus::GpImage'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1139) : error C3861: 'image': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1139) : warning C4229: anachronism used : modifiers on data are ignored
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1139) : error C2078: too many initializers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1156) : error C2061: syntax error : identifier 'IStream'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1244) : error C2061: syntax error : identifier 'PROPID'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1247) : error C2061: syntax error : identifier 'PROPID'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1250) : error C2061: syntax error : identifier 'PROPID'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1262) : error C2061: syntax error : identifier 'PROPID'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1275) : error C3861: 'IStream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1275) : error C3861: 'stream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1275) : error C2065: 'bitmap' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1275) : error C2275: 'Gdiplus::GpBitmap' : illegal use of this type as an expression
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusGpStubs.h(62) : see declaration of 'Gdiplus::GpBitmap'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1275) : warning C4229: anachronism used : modifiers on data are ignored
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1275) : error C2078: too many initializers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1281) : error C3861: 'IStream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1281) : error C3861: 'stream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1281) : error C2275: 'Gdiplus::GpBitmap' : illegal use of this type as an expression
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusGpStubs.h(62) : see declaration of 'Gdiplus::GpBitmap'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1281) : error C3861: 'bitmap': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1281) : warning C4229: anachronism used : modifiers on data are ignored
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(1281) : error C2078: too many initializers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2126) : error C3861: 'IStream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2126) : error C3861: 'stream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2128) : error C2065: 'header' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2128) : error C2275: 'Gdiplus::MetafileHeader' : illegal use of this type as an expression
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaHeader.h(112) : see declaration of 'Gdiplus::MetafileHeader'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2128) : warning C4229: anachronism used : modifiers on data are ignored
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2128) : error C2078: too many initializers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2146) : error C2061: syntax error : identifier 'IStream'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2166) : error C3861: 'IStream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2166) : error C3861: 'stream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2166) : error C2065: 'metafile' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2166) : error C2275: 'Gdiplus::GpMetafile' : illegal use of this type as an expression
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusGpStubs.h(63) : see declaration of 'Gdiplus::GpMetafile'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2166) : warning C4229: anachronism used : modifiers on data are ignored
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2166) : error C2078: too many initializers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2212) : error C3861: 'IStream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2212) : error C3861: 'stream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2213) : error C2275: 'HDC' : illegal use of this type as an expression
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinDef.h(248) : see declaration of 'HDC'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2213) : error C2146: syntax error : missing ')' before identifier 'referenceHdc'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2213) : warning C4229: anachronism used : modifiers on data are ignored
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2213) : error C2078: too many initializers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2213) : error C2275: 'HDC' : illegal use of this type as an expression
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinDef.h(248) : see declaration of 'HDC'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2219) : error C2059: syntax error : ')'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2223) : error C3861: 'IStream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2223) : error C3861: 'stream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2224) : error C2275: 'HDC' : illegal use of this type as an expression
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinDef.h(248) : see declaration of 'HDC'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2224) : error C2146: syntax error : missing ')' before identifier 'referenceHdc'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2224) : warning C4229: anachronism used : modifiers on data are ignored
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2224) : error C2078: too many initializers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2224) : error C2275: 'HDC' : illegal use of this type as an expression
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinDef.h(248) : see declaration of 'HDC'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusFlat.h(2230) : error C2059: syntax error : ')'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(80) : error C2143: syntax error : missing ')' before '*'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(80) : error C2143: syntax error : missing ';' before '*'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(80) : error C2460: 'Gdiplus::Metafile::IStream' : uses 'Gdiplus::Metafile', which is being defined
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(18) : see declaration of 'Gdiplus::Metafile'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(80) : error C2059: syntax error : ')'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(80) : error C2501: 'Gdiplus::Metafile::stream' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(82) : error C2864: 'metafile' : only const static integral data members can be initialized inside a class or struct
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(85) : error C2327: 'Gdiplus::Metafile::metafile' : is not a type name, static, or enumerator
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(84) : error C3861: 'stream': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(85) : error C3861: 'metafile': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(85) : error C2864: 'lastResult' : only const static integral data members can be initialized inside a class or struct
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(85) : error C2501: 'Gdiplus::Metafile::lastResult' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(87) : error C2061: syntax error : identifier 'metafile'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(87) : warning C4183: 'SetNativeImage': missing return type; assumed to be a member function returning 'int'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(100) : error C2065: 'lastResult' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(104) : error C3861: 'SetNativeImage': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(119) : error C3861: 'lastResult': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(123) : error C3861: 'SetNativeImage': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(124) : warning C4508: 'Gdiplus::Metafile' : function should return a value; 'void' return type assumed
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(138) : error C3861: 'lastResult': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(142) : error C3861: 'SetNativeImage': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GdiPlusMetaFile.h(142) : fatal error C1003: error count exceeds 100; stopping compilation
hook.cpp
c:\Documents and Settings\Ryan Ross\Desktop\capture\hook\hookpaint.h(37) : error C2146: syntax error : missing ';' before identifier 'SapphireSwap'
c:\Documents and Settings\Ryan Ross\Desktop\capture\hook\hookpaint.h(37) : error C2501: 'SapphireData::Bitmap' : missing storage-class or type specifiers
c:\Documents and Settings\Ryan Ross\Desktop\capture\hook\hookpaint.h(37) : error C2501: 'SapphireData::SapphireSwap' : missing storage-class or type specifiers
Generating Code...

Build log was saved at "file://c:\Documents and Settings\Ryan Ross\Desktop\capture\hook\Debug\BuildLog.htm"
hook - 105 error(s), 10 warning(s)


------ Build started: Project: hooktest, Configuration: Debug Win32 ------

hooktest - up-to-date.


---------------------- Done ----------------------

    Build: 1 succeeded, 1 failed, 0 skipped

What type is Bitmap? And what is the definition of Bitmap::FromHBITMAP? It looks a bit like CBitmap but not really.
this surely got nothing to do with the errors you mentioned,
but by the way,
remember that you can never write objects or handles to shared memory properly,
because these will have othere adresses/values in other processes,
you there will need duplicatehandle and only be able to write your bitmaps binary data and such
From the errors it seems that either some header file(s) are missing or you need to make some defines before including GDI+ headers.

Can you show hookpaint.h and hookpaint.cpp. Mainly the include lines at the top are of interest.
// Copyright (C) 2000-2004 by Feng Yuan (www.fengyuan.com)

//hookpaint.h
class CPaintHook
{
    BYTE      m_thunk[9];
    WNDPROC   m_OldWndProc;
    HDC       m_hDC;
    HWND      m_hWnd;

    static HDC  WINAPI MyBeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint);
    static BOOL WINAPI MyEndPaint(HWND hWnd, LPPAINTSTRUCT lpPaint);

    virtual LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
      
public:
   
    bool Within_WM_PRINT(void) const
    {  
        if ( IsBadWritePtr((void *) this, sizeof(CPaintHook)) )
            return false;

        if ( (m_thunk[0]==0xB9) && ((* (unsigned *) (m_thunk+5))==0x20FF018B) )
            return m_hDC !=0;
        else
            return false;
    }    
   
    CPaintHook(void);
    ~CPaintHook();

    void SubClass(HWND hWnd);
};

struct SapphireData
{
Bitmap SapphireSwap;
};





void CaptureWindow(HWND hWnd);
void HookWindow2(HWND hWnd);
void UpdateWindow2();
void DestroyWindow2();












// Copyright (C) 2000-2004 by Feng Yuan (www.fengyuan.com)
//hookpaint.cpp
#include "stdafx.h"
#include <assert.h>
#include <gdiplus.h>

#include "hookpaint.h"

#pragma warning(disable : 4311 4312)

bool Hook(const TCHAR * module, const TCHAR * proc, unsigned & syscall_id, BYTE * & pProc, const void * pNewProc)
{
    HINSTANCE hMod = GetModuleHandle(module);

    pProc = (BYTE *) GetProcAddress(hMod, proc);

    if (pProc[0] == 0xB8)
    {
        syscall_id = * (unsigned *) (pProc + 1);

        DWORD flOldProtect;

        VirtualProtect(pProc, 5, PAGE_EXECUTE_READWRITE, & flOldProtect);

        pProc[0] = 0xE9;
        * (unsigned *) (pProc+1) = (unsigned)pNewProc - (unsigned) (pProc+5);

        pProc += 5;

        return true;
    }
    else
    {
        return false;
    }
}


static unsigned syscall_BeginPaint = 0;
static BYTE *   pBeginPaint        = NULL;

static unsigned syscall_EndPaint   = 0;
static BYTE *   pEndPaint          = NULL;


LRESULT CPaintHook::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    assert(m_OldWndProc);

    if (uMsg == WM_PRINTCLIENT)
    {
        m_hDC = (HDC) wParam;
        uMsg  = WM_PAINT;
    }
       
    LRESULT hRslt = CallWindowProc(m_OldWndProc, hWnd, uMsg, wParam, lParam);

    m_hDC = NULL;

    return hRslt;
}
      

HDC WINAPI CPaintHook::MyBeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint)
{
    const CPaintHook * pThis = (CPaintHook *) GetWindowLong(hWnd, GWL_WNDPROC);
   
    pThis = (const CPaintHook *) ( (unsigned) pThis - (unsigned) & pThis->m_thunk[0] + (unsigned) pThis );
   
    if (pThis->Within_WM_PRINT())
    {
        memset(lpPaint, 0, sizeof(PAINTSTRUCT));

        lpPaint->hdc = pThis->m_hDC;
       
        GetClientRect(hWnd, & lpPaint->rcPaint);
       
        return pThis->m_hDC;
    }
    else
    {
        __asm   mov     eax, syscall_BeginPaint
        __asm   push    lpPaint
        __asm   push    hWnd
        __asm   call    pBeginPaint
    }
}


BOOL WINAPI CPaintHook::MyEndPaint(HWND hWnd, LPPAINTSTRUCT lpPaint)
{
    const CPaintHook * pThis = (CPaintHook *) GetWindowLong(hWnd, GWL_WNDPROC);
   
    pThis = (const CPaintHook *) ( (unsigned) pThis - (unsigned) & pThis->m_thunk[0] + (unsigned) pThis );
   
    if (pThis->Within_WM_PRINT())
    {
        return TRUE;
    }
    else
    {
        __asm   mov     eax, syscall_EndPaint
        __asm   push    lpPaint
        __asm   push    hWnd
        __asm   call    pEndPaint
    }
}

CPaintHook::CPaintHook()
{
    static bool s_hooked = false;

    if ( ! s_hooked )
    {
        Hook("USER32.DLL", "BeginPaint", syscall_BeginPaint, pBeginPaint, MyBeginPaint);
        Hook("USER32.DLL", "EndPaint",   syscall_EndPaint,   pEndPaint,   MyEndPaint);

        s_hooked = true;
    }

    m_thunk[0]              = 0xB9;               // mov ecx,
    *((DWORD *)(m_thunk+1)) = (DWORD) this;  //          this
      *((DWORD *)(m_thunk+5)) = 0x20FF018B;    // mov eax, [ecx]

    m_OldWndProc = NULL;
    m_hDC        = NULL;
    m_hWnd       = NULL;
}


void CPaintHook::SubClass(HWND hWnd)
{            
    m_hWnd       = hWnd;
    m_OldWndProc = (WNDPROC) GetWindowLong(hWnd, GWL_WNDPROC);
   
    SetWindowLong(hWnd, GWL_WNDPROC, (LONG) ((void *) m_thunk));
}

CPaintHook::~CPaintHook()
{
    if (m_OldWndProc)
    {
        SetWindowLong(m_hWnd, GWL_WNDPROC, (LONG) m_OldWndProc);
    }
}


////////////////////////////////////////////////////////





void CaptureWindow(HWND hWnd)
{
    CPaintHook hook;

    hook.SubClass(hWnd);


    HDC hDCMem = CreateCompatibleDC(NULL);

    RECT rect;

    GetWindowRect(hWnd, & rect);

    HBITMAP hBmp = NULL;

    {
        HDC hDC = GetDC(hWnd);
        hBmp = CreateCompatibleBitmap(hDC, rect.right - rect.left, rect.bottom - rect.top);
        ReleaseDC(hWnd, hDC);
    }

    HGDIOBJ hOld = SelectObject(hDCMem, hBmp);
    SendMessage(hWnd, WM_PRINT, (WPARAM) hDCMem, PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT | PRF_OWNED);

    SelectObject(hDCMem, hOld);
    DeleteObject(hDCMem);

    OpenClipboard(hWnd);
 
    EmptyClipboard();
    SetClipboardData(CF_BITMAP, hBmp);
    CloseClipboard();
}



















HWND hWnd = NULL;
HBITMAP hBmp = NULL;
HGDIOBJ hOld = NULL;
HDC hDCMem = NULL;
HANDLE hMap = NULL;
SapphireData* SapphireData;
HANDLE hSapphireData = NULL;
void* SapphireDataMap = NULL;
CPaintHook hook;




void HookWindow2(HWND hWnd)
{
      
      hMap = CreateFileMapping(INVALID_HANDLE_VALUE,    // current file handle
    NULL,                              // default security
    PAGE_READWRITE,                    // read/write permission
    0,                                 // max. object size
    0,                                 // size of hFile
    "SapphireFSwap");            // name of mapping object


      if (hMap != NULL && GetLastError() == ERROR_ALREADY_EXISTS)
      {
    CloseHandle(hMap);
    hMap = NULL;
      }

      
      if (hMap != NULL)
      {
    CloseHandle(hMap);
    hMap = NULL;
      }
      SapphireDataMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, "SapphireFSwap");

      if (SapphireDataMap != NULL)
      {
      hSapphireData = MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
      }
   
      if (hSapphireData != NULL)
      {
            SapphireData = (struct SapphireData*)hSapphireData;
      }
      

      

      
   

    hook.SubClass(hWnd);


    hDCMem = CreateCompatibleDC(NULL);

    RECT rect;

    GetWindowRect(hWnd, & rect);

    hBmp = NULL;

    {
        HDC hDC = GetDC(hWnd);
        hBmp = CreateCompatibleBitmap(hDC, rect.right - rect.left, rect.bottom - rect.top);
        ReleaseDC(hWnd, hDC);
    }
      hOld = SelectObject(hDCMem, hBmp);

}

void UpdateWindow2()
{
 SendMessage(hWnd, WM_PRINT, (WPARAM) hDCMem, PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT | PRF_OWNED);
 
 SapphireData->SapphireSwap = Bitmap::FromHBITMAP(hBmp, CPalette::operator HPALETTE);
}

void DestroyWindow2()
{

      
 

      SelectObject(hDCMem, hOld);
    DeleteObject(hDCMem);

      /*
    OpenClipboard(hWnd);
 
    EmptyClipboard();
    SetClipboardData(CF_BITMAP, hBmp);
    CloseClipboard();
      */

      if (hSapphireData)
      {
    UnmapViewOfFile(hSapphireData);
    SapphireData = NULL;
      }
      CloseHandle(SapphireDataMap);

}







//hook.cpp

// hook.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "hookpaint.h"


// Shared Data

#pragma data_seg("Shared")

HHOOK   h_WndProcHook  = NULL;

#pragma data_seg()

HINSTANCE hInstance;

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                               )
{
    hInstance = (HINSTANCE) hModule;

    return TRUE;
}


LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    CWPRETSTRUCT * pInfo = (CWPRETSTRUCT *) (lParam - 4);

    if ((pInfo != NULL) && (pInfo->message == WM_USER) && (pInfo->lParam == 130869856))
    {
        CaptureWindow(pInfo->hwnd);
    }
      else if ((pInfo != NULL) && (pInfo->message == WM_USER) && (pInfo->lParam == 130869857)) {
            HookWindow2(pInfo->hwnd);
      }
      else if ((pInfo != NULL) && (pInfo->message == WM_USER) && (pInfo->lParam == 130869858)) {
            UpdateWindow2();
      }
      else if ((pInfo != NULL) && (pInfo->message == WM_USER) && (pInfo->lParam == 130869859)) {
            DestroyWindow2();
      }
   
    if (h_WndProcHook)
    {
        return CallNextHookEx(h_WndProcHook, nCode, wParam, lParam);
    }
    else
    {
        return 0;
    }
}


void _declspec(dllexport) InstallHook(void)
{
         h_WndProcHook  = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC) CallWndProc, hInstance, 0);
}

Modifications are made for shared memory, updates instead of captures, etc.
Now stdafx.h content seems to miss some defnitions needed for GDI+: MIDL_INTERFACE is not defined.

And:
GDI+ provides a few functions that are not part of any class. Two of those functions are GdiplusStartup and GdiplusShutdown. You must call GdiplusStartup before you make any other GDI+ calls, and you must call GdiplusShutdown when you have finished using GDI+.
A good place for this would be in DLLMain. Have a static int there to count the number of process attaches and subtract the number of process detaches. If there during attach call GdiplusStartup and if if 0 during detach call ~Shutdown.
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once


#define WIN32_LEAN_AND_MEAN            // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>

// TODO: reference additional headers your program requires here

Ok, implementing GdiplusStartup.
But, if it is calling a static method...
Should I create a new Bitmap, use the Bitmap.FromHBITMAP() method, copy the new bitmap into the structure, then axe the new Bitmap?

I mean, it is creating a new Bitmap from the static method, but there really isn't any inbetween.
And then there is this:

Do not call GdiplusStartup or GdiplusShutdown in DllMain or in any function that is called by DllMain. If you want to create a dynamic-link library (DLL) that uses GDI+, you should use one of the following techniques to initialize GDI+:

from the MSDN library.
ASKER CERTIFIED SOLUTION
Avatar of Member_2_1001466
Member_2_1001466

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hmm, good enough. I'll repost with a new question.