Thread: message box LPCWSTR manipulation and keyword question

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    222

    message box LPCWSTR manipulation and keyword question

    I'm trying to implement the string manipulation as shown below:
    Code:
    HRESULT __stdcall
    COemUni2::
    QueryInterface(
        const IID&  iid,
        void**      ppv
        )
    {
        OEMDBG(DBG_VERBOSE, L"COemUni2::QueryInterface() entry.");
    
    	//---------------------------------------------------------------------------
    	// adding debugging dialog boxes
    	LPCWSTR showtext;
    
    	// I want to show in the body of the dialog box
    	// "iid = *value of iid*\nppv = *value of ppv*"
    
    	int msgboxID = MessageBox(
    		NULL,
    		(LPCWSTR),
    		(LPCWSTR) L"Debug Dialog Box",
    		MB_OK);
    	//---------------------------------------------------------------------------
    
        if (iid == IID_IUnknown)
        {
            *ppv = static_cast<IUnknown*>(this);
            VERBOSE(DLLTEXT("COemUni2::QueryInterface IUnknown.\r\n"));
        }
        else if (iid == IID_IPrintOemUni2)
        {
            VERBOSE(DLLTEXT("COemUni2::QueryInterface IPrintOemUni2.\r\n"));
    
            *ppv = static_cast<IPrintOemUni2*>(this);
        }
        else
        {
            WARNING(DLLTEXT("COemUni2::QueryInterface NULL. Returning E_NOINTERFACE.\r\n"));
    
            *ppv = NULL;
            return E_NOINTERFACE;
        }
        reinterpret_cast<IUnknown*>(*ppv)->AddRef();
        return S_OK;
    }
    I have thought about strcpy() and strcat() functions, however, I'm not sure how well they would work. Does anyone have a more appropriate suggestion?

    Secondly, I'm not sure what the keyword void** of the parameter of this function mean. Does this mean pointer to a pointer?

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    If you don't have access to CString in your code, you can use swprintf to print your values to a wchar_t array:

    Code:
    wchar_t text[100];
    
    swprintf( L"iid = &#37;p\nppv = %p", iid, ppv );
    
    MessageBox( NULL, text, L"Debug Dialog Box", MB_OK);
    If that is really what you want is up to you. It will be just numbers.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    If you want to see the full GUID value of the IID, I use this in a printf-style format specification:
    Code:
    #define GUID_Format L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"
    #define GUID_Printf(guid) \
        guid.Data1, guid.Data2, guid.Data3, \
        guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], \
        guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]
    
    ...
    
    wchar_t text[100];
    
    swprintf(L"iid = " 
             GUID_Format
             L"\nppv = %p", GUID_Printf(iid), ppv);
    
    MessageBoxW(0, text, L"Debug Dialog Box", MB_OK);
    gg

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    222
    Thank you for your suggestion. However, I'm getting the following compiling error for this line:
    Code:
    swprintf(L"iid = " 
             GUID_Format
             L"\nppv = &#37;p", GUID_Printf(iid), ppv);
    It's apparently complaining about the blue highlighted parameter about:
    Code:
    e:\research\oemdll\oemuni\intrface.cpp(91) : error C2664: 'swprintf' : cannot co
    nvert parameter 2 from 'const unsigned long' to 'const wchar_t *'
    Does this entail type casting of something like:
    (const wchar *) (GUID_Printf(iid)) for the second parameter? Thanks.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Try:
    Code:
    swprintf(text, L"iid = " 
             GUID_Format
             L"\nppv = &#37;p", GUID_Printf(iid), ppv);
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Jul 2004
    Posts
    222
    Thanks, Elysia. I guess that's problem solved for now. What would be your general guideline in terms of converting DWORD, PDWORD, and PVOID type parameters of another function?

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Are you talking about converting X -> const TCHAR*?
    Or X -> Y?
    All may require different approaches.
    Btw, PDWORD = DWORD* and PVOID = void*
    Microsoft evil pointer typedefs.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Jul 2004
    Posts
    222
    I'm talking about displaying the parameters of this function in a messagebox in similar fashion as the previous question on the same thread:
    Code:
    HRESULT __stdcall
    COemUni2::
    GetInfo(
        DWORD       dwMode,
        PVOID       pBuffer,
        DWORD       cbSize,
        PDWORD      pcbNeeded
        )
    I'm not entirely sure what you mean by converting X -> const TCHAR* or X -> Y.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I meant "any type to const TCHAR*" and "any type to another type."
    TCHAR is typically a macro that means either ansi or unicode, btw.
    But as for the question, you can display any parameters using (w)sprintf. Look in the manual and you'll find what syntax you should use to convert them into a string.
    Any type that begins with P* in windows APIs is a pointer (ie PDWORD = DWORD*).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Jul 2004
    Posts
    222
    One last question with respect to windows messagebox and MS typedefs: why are there L's in front of some strings? For example:

    Code:
    swprintf(text, L"iid = " 
             GUID_Format
             L"\nppv = &#37;p", GUID_Printf(iid), ppv);

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    L means unicode string.
    const wchar_t* p = L"My string";
    const char* p2 = "My string";
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    L means wide characters. Wide character might be unicode, but they might not. On Windows, I think it is.

Popular pages Recent additions subscribe to a feed