Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In a c++ project Iam using a HeaderFile localcpc.h.Inside that an error is arising
''AfxMessageBox' : none of the 2 overloads could convert all the argument types'

And the error is coming in the below part of code:

C#
BOOL SetLogNameAndPath(LPCWSTR FileNameandPath)
    {
        if(FileNameandPath)
        {
            FileHandle = CreateFile(FileNameandPath,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
            if(FileHandle == INVALID_HANDLE_VALUE)
            {
                AfxMessageBox("Unable to create Log File");
                return FALSE;
            }
            SetFilePointer(FileHandle,0L,NULL,FILE_END);
        }
        else
        {
            ::AfxMessageBox(L"No FileName and path specified");
            return FALSE;
        }
        return TRUE;
    }



Can anybody suggest some solution?
Posted

1 solution

If AfxMessageBox which is defined as

int AfxMessageBox( LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0 );


cannot take your L"No FileName and path specified" LPCWSTR parameter and fill in the remaining two with defaults it's almost certainly because you're building a Multibyte build or have otherwise failed to predfine UNICODE and _UNICODE in your build meaning that the preprocessor resolved definition of AfxMessageBox is in fact

int AfxMessageBox( const char* lpszText, unsigned int nType = MB_OK, unsigned int nIDHelp = 0 );


which no longer matches the use of LPCWSTR resulting from the L"text" macro.

You need to either build a UNICODE build or use _T("No FileName and path specified") which will work in both UNICODE and non UNICODE builds.
 
Share this answer
 
Comments
danil33 14-Mar-13 7:01am    
As per the suggestion I changed the code like below:

BOOL SetLogNameAndPath(LPCWSTR FileNameandPath)
{
if(FileNameandPath)
{
FileHandle = CreateFile(FileNameandPath,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(FileHandle == INVALID_HANDLE_VALUE)
{
AfxMessageBox _T("Unable to create Log File");
return FALSE;
}
SetFilePointer(FileHandle,0L,NULL,FILE_END);
}
else
{
AfxMessageBox _T("No FileName and path specified");
return FALSE;
}
return TRUE;
}

And now it is showing error:
error C2143: syntax error : missing ';' before 'string'
Matthew Faithfull 14-Mar-13 7:08am    
That wasn't quite what I was suggesting try:
AfxMessageBox( _T("No FileName..." ) );
One set of brackets for the _T Macro and one for the function call.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900