Regex y expresión de puntero nulo no válida

I found this website from google and I assume that here people helps with coding problems.

I am creating a badword filter to an application, but I have ran into problems. Currently I am creating a thread from the applications entry point, and the thread flow goes like this:

while(true)
{

    if (!OpenClipboard(NULL))
        ExitProcess(0); //TODO: Try opening clipboard again.

    h = GetClipboardData(CF_TEXT); //h is HANDLE.

    std::string CB_Data = (char*)h;

    if(CB_Data.size() != NULL) //An attempt to check if it's not empty
    {
        if ( std::regex_search(CB_Data.c_str(), BADWORD_FILTER))
        {
            try
            {
                EmptyClipboard();
                SetClipboardData(CF_TEXT, INFORMATION); //INFORMATION is converted to char from HANDLE. INFORMATION = "Bad word filter detected forbidden words pattern."
            }
            catch(...)
            {
                //TODO: Error logging
            }
        }

        else if ( std::regex_search(CB_Data.c_str(), BADWORD_FILTER2))
        {
            try
            {
                EmptyClipboard();
                SetClipboardData(CF_TEXT, INFORMATION); //INFORMATION is converted to char from HANDLE. INFORMATION = "Bad word filter detected forbidden words pattern."
            }
            catch(...)
            {
                //TODO: Error logging
            }
            EmptyClipboard();
            SetClipboardData(CF_TEXT, INFORMATION); //INFORMATION is converted to char from HANDLE. INFORMATION = "Bad word filter detected forbidden words pattern."
        }
    }

    CloseClipboard();
    Sleep(1000); //Check every 1 second for the forbidden words.
}

So this application monitors clipboard from forbidden words. However, most of the time I run into an "Expression: Invalid null pointed" -error, and I am not familiar with Visual Studio debugger. I tried, but obviously didn't success very well.

Aquí está el error: http://i.stack.imgur.com/wACnA.png

Cualquier ayuda será enormemente apreciada, gracias.

preguntado el 28 de enero de 14 a las 18:01

Your error says the exception occurred on line 930. Which line in the snippet you posted is 930? -

Line 930 is from ../include/xstring - which is included from #include <regex> -

Hopefully someone can help. -

1 Respuestas

Obtienes un error porque GetClipboardData() no devuelve un const char* puntero y el std::string constructor tries to read your parameter as a const char*.

As you state in the question, GetClipboardData() devuelve un HANDLE. Vea este topic for a correct example how to use this function.

Otros consejos útiles:

  • Press the "Retry" button and you will land in the debugger. Using the debugger you can see exactly where your program went wrong
  • CB_Data.size() is an unsigned integer value (the length of the string), not a pointer. Do not compare it with NULL!

contestado el 23 de mayo de 17 a las 11:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.