Compiler Error with script

This is a discussion on Compiler Error with script within the C++ Programming forums, part of the General Programming Boards category; I tried compileing this script: Code: #include <windows.h> /* * This function is a wrapper for the shell function SHMessageBoxCheck. ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Exclamation Compiler Error with script

    I tried compileing this script:
    Code:
    #include <windows.h>
    
    /*
     * This function is a wrapper for the shell function SHMessageBoxCheck.
     *
     * See the documentation for SHMessageBoxCheck at:
     * http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/shlwapi/others/shmessageboxcheck.asp
     *
     * The ordinals were provided by a usenet post:
     * http://groups-beta.google.com/group/microsoft.public.platformsdk.shell/msg/d638e49f001752b4
     */
    int MessageBoxCheck(HWND hwnd, LPCTSTR pszText, LPCTSTR pszTitle, UINT uType, int iDefault, LPCTSTR pszRegVal)
    {
    	typedef (WINAPI * PSHMBC) (HWND, LPCTSTR, LPCTSTR, UINT, int, LPCTSTR);
    
    	HMODULE hShlwapi          = NULL; 
    	PSHMBC  shMessageBoxCheck = NULL;
    	int     retValue          = -1;
    	WORD    ordinalSHMBC      = (sizeof(TCHAR) == sizeof(WCHAR) ? 191 : 185);
    
    	hShlwapi = LoadLibrary(TEXT("shlwapi.dll"));
    
    	if (hShlwapi)
    	{
    		shMessageBoxCheck = (PSHMBC) GetProcAddress(hShlwapi, (LPCSTR) ordinalSHMBC);
    
    		if (shMessageBoxCheck)
    		{
    			/* For some reason SHMessageBoxCheck seems to require that the thread has a
    			 * message queue to work correctly. So we call PeekMessage to force the
    			 * creation of a message queue. */
    			MSG msg; PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
    
    			retValue = shMessageBoxCheck(hwnd, pszText, pszTitle, uType, iDefault, pszRegVal);
    		}
    
    		FreeLibrary(hShlwapi);
    	}
    
    	return retValue;
    }
    
    /*
     * Sample showing how to use MessageBoxCheck.
     * Note: You must provide a new guid before using this code in a distributed program.
     */
    int main(void)
    {
    	if (-1 == MessageBoxCheck( NULL, TEXT("Your computer is broken."), TEXT("Warning"),
    	                           MB_OK | MB_ICONEXCLAMATION, IDOK,
    	                           TEXT("{D85055F7-4AD0-49d9-9686-35F5A53B2233}") ))
    	{
    		/* If our checked box message box failed, show an ordinary message box. */
    		MessageBox(NULL, TEXT("Your computer is broken."), TEXT("Warning"),
    		           MB_OK | MB_ICONEXCLAMATION);
    	}
    }
    But an error came up.
    ISO C++ forbids declaration of 'PSHMBC' with no type
    Why is it doing this?
    I am using "Dev-C++" compiler.

    Thanks in advance, August.

  2. #2
    Registered User
    Join Date
    Apr 2005
    Posts
    3
    Sorry, I really have no idea. The code looks fine to me, maybe the error means that you need to declare something before you use the PSHMBC, like to use cout you need the "#include<iostream>" Hope that helps.

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    920
    PSHMBC shMessageBoxCheck = NULL;
    Perhaps? Although I'm not sure that's what the error message was referring to. It's probably syntactic. I too cannot find it.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,854
    > typedef (WINAPI * PSHMBC) (HWND, LPCTSTR, LPCTSTR, UINT, int, LPCTSTR);
    Because M$ header files are so riddled with #defines which may or may not apply in any given case, it's really hard to figure out what the compiler is actually seeing from this statement.

    Code:
    g++ -E hello.cpp -o hello.i
    This allows you to see the code the compiler actually sees (after all files have been included, and all #defines expanded etc). The produced file is quite large, and right at the end will be your code.
    Look at the typedef again, and decide whether it's correct or not (or post it's expanded version here).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Do I put that code in the linker?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 05:04 AM
  2. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 12:07 PM
  3. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  4. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM
  5. Help With finding a compiler
    By macman in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-15-2005, 09:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21