User forums > Using Code::Blocks

RunningTask was not declared in this scope

(1/3) > >>

Cloud_Strife_Han:
Hi you guys, It's the first time I used code::block to build a project. So I encounter some problems.

When I use VS2012 to build a example code[below] from msdn, it's completely successful. But it is opposite with Code::Block. I figured the problem occured when linking library or something similar, so I have to add "C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x86" to Search Directories. I alse add name of using library into Linker Settings. But I still dont work, it show some error about library! I checked file dll in my computer then it exist.

This is my code:


--- Code: ---> #define _WIN32_DCOM
>
> #include <windows.h>
> #include <iostream>
> #include <stdio.h>
> #include <comdef.h> //  Include the task header file.
> #include <taskschd.h>
> #pragma comment(lib, "taskschd.lib")
> #pragma comment(lib, "comsupp.lib")
>
>
> using namespace std;
>
> int __cdecl wmain() {
>     //  ------------------------------------------------------
>     //  Initialize COM.
>     HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
>     if( FAILED(hr) )
>     {
>         printf("\nCoInitializeEx failed: %x", hr );
>         return 1;
>     }
>
>     //  Set general COM security levels.
>     hr = CoInitializeSecurity(
>         NULL,
>         -1,
>         NULL,
>         NULL,
>         RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
>         RPC_C_IMP_LEVEL_IMPERSONATE,
>         NULL,
>         0,
>         NULL);
>
>     if( FAILED(hr) )
>     {
>         printf("\nCoInitializeSecurity failed: %x", hr );
>         CoUninitialize();
>         return 1;
>     }
>
>     //  ------------------------------------------------------
>     //  Create an instance of the Task Service.
>     ITaskService *pService = NULL;
>     hr = CoCreateInstance( CLSID_TaskScheduler,
>                            NULL,
>                            CLSCTX_INPROC_SERVER,
>                            IID_ITaskService,
>                            (void**)&pService );
>     if (FAILED(hr))
>     {
>           printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
>           CoUninitialize();
>           return 1;
>     }
>
>     //  Connect to the task service.
>     hr = pService->Connect(_variant_t(), _variant_t(),
>         _variant_t(), _variant_t());
>     if( FAILED(hr) )
>     {
>         printf("ITaskService::Connect failed: %x", hr );
>         pService->Release();
>         CoUninitialize();
>         return 1;
>     }
>
>      // Get the running tasks.
>      IRunningTaskCollection* pRunningTasks = NULL;
>      hr = pService->GetRunningTasks(TASK_ENUM_HIDDEN, &pRunningTasks);
>
>     pService->Release();
>     if( FAILED(hr) )
>     {
>         printf("Cannot get Root Folder pointer: %x", hr );
>         CoUninitialize();
>         return 1;
>     }
>
>     LONG numTasks = 0;
>     hr = pRunningTasks->get_Count(&numTasks);
>
>     if( numTasks == 0 )
>      {
>         printf("\nNo Tasks are currently running" );
>         pRunningTasks->Release();
>         CoUninitialize();
>         return 1;
>      }
>
>     printf("\nNumber of running tasks : %d", numTasks );
>
>     TASK_STATE taskState;
>
>     for(LONG i=0; i < numTasks; i++)
>     {
>         IRunningTask* pRunningTask = NULL;
>         hr = pRunningTasks->get_Item( _variant_t(i+1), &pRunningTask );
>
>         if( SUCCEEDED(hr) )
>         {
>             BSTR taskName = NULL;
>             hr = pRunningTask->get_Name(&taskName);
>             if( SUCCEEDED(hr) )
>             {
>                 printf("\nTask Name: %S", taskName);
>                 SysFreeString(taskName);
>
>                 hr = pRunningTask->get_State(&taskState);
>                 if (SUCCEEDED (hr) )
>                     printf("\n\tState: %d", taskState);
>                 else
>                     printf("\n\tCannot get the registered task state: %x", hr);
>             }
>             else
>             {
>                 printf("\nCannot get the registered task name: %x", hr);
>             }
>             pRunningTask->Release();
>         }
>         else
>         {
>             printf("\nCannot get the registered task item at index=%d: %x", i+1, hr);
>         }
>     }
>
>     pRunningTasks->Release();
>     CoUninitialize();
>     return 0; }
--- End code ---

And I got these errors


--- Quote ---|=== Build: Debug in TaskScheduler (compiler: GNU GCC Compiler) ===|
E:\WorkSpace\Code\TaskScheduler\main.cpp|9|warning: ignoring #pragma comment  [-Wunknown-pragmas]|
E:\WorkSpace\Code\TaskScheduler\main.cpp|10|warning: ignoring #pragma comment  [-Wunknown-pragmas]|
E:\WorkSpace\Code\TaskScheduler\main.cpp||In function 'int wmain()':|
E:\WorkSpace\Code\TaskScheduler\main.cpp|22|warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]|
E:\WorkSpace\Code\TaskScheduler\main.cpp|40|warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]|
E:\WorkSpace\Code\TaskScheduler\main.cpp|47|error: 'ITaskService' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|47|error: 'pService' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|48|error: 'CLSID_TaskScheduler' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|51|error: 'IID_ITaskService' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|55|warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]|
E:\WorkSpace\Code\TaskScheduler\main.cpp|65|warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]|
E:\WorkSpace\Code\TaskScheduler\main.cpp|72|error: 'IRunningTaskCollection' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|72|error: 'pRunningTasks' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|73|error: 'TASK_ENUM_HIDDEN' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|78|warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]|
E:\WorkSpace\Code\TaskScheduler\main.cpp|94|warning: format '%d' expects argument of type 'int', but argument 2 has type 'LONG {aka long int}' [-Wformat=]|
E:\WorkSpace\Code\TaskScheduler\main.cpp|96|error: 'TASK_STATE' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|100|error: 'IRunningTask' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|100|error: 'pRunningTask' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|112|error: 'taskState' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|116|warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]|
E:\WorkSpace\Code\TaskScheduler\main.cpp|120|warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]|
E:\WorkSpace\Code\TaskScheduler\main.cpp|126|warning: format '%d' expects argument of type 'int', but argument 2 has type 'long int' [-Wformat=]|
E:\WorkSpace\Code\TaskScheduler\main.cpp|126|warning: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'HRESULT {aka long int}' [-Wformat=]|
||=== Build failed: 11 error(s), 12 warning(s) (0 minute(s), 1 second(s)) ===|
--- End quote ---

Any ideas for my problem?
Thank for reading! Sorry for my bad english.

BlueHazzard:
Hi,
first of all codeblocks is not a compiler. So technically you do not compile with codeblocks but with gcc. So you use a new compiler to compile your code. If you have any problems and you search the web you should not search for "help compiler error codeblocks" but "help compiler error gcc"

Second. Thank you for providing source and some build messages. But we need other information:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

also:

--- Quote ---E:\WorkSpace\Code\TaskScheduler\main.cpp|47|error: 'ITaskService' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|47|error: 'pService' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|48|error: 'CLSID_TaskScheduler' was not declared in this scope|
E:\WorkSpace\Code\TaskScheduler\main.cpp|51|error: 'IID_ITaskService' was not declared in this scope|
--- End quote ---
this are not linker but compiler errors, so you are missing a header here.

BTW. you can use codeblocks also with the msvc compiler so it should compile straight the way...

Cloud_Strife_Han:
Thank for your reply.

I am sure I have linked the header into code::block (Build Option -> Linker Setting -> Add and type the header name) it still doesnt work!

I'm using code::block version 17.04 on windows 7 with TDM-GCC MinGW Compiler (ver 5.1.0). This occur happens immedialy when I build project.

I attempted to:
1. Linking the header
2. Add Search Directories
3. Copy header files into project then add as #include "header" then I see no error about library, just has last one error ||error: ld returned 1 exit status|!

BlueHazzard:

--- Quote ---I am sure I have linked the header into code::block (Build Option -> Linker Setting -> Add and type the header name) it still doesnt work!
--- End quote ---

Header (compiler) file: https://en.wikipedia.org/wiki/Include_directive
vs
Library (linker) https://en.wikipedia.org/wiki/Library_(computing)

and to help you we need the full rebuild log as is described in the FAQs and not the build messages

Cloud_Strife_Han:
This is my build log:


--- Quote ----------------- Build: Debug in TaskScheduler (compiler: GNU GCC Compiler)---------------

x86_64-w64-mingw32-g++.exe -Wall -g -std=c++98 -IC:\wxWidgets-3.1.0\lib\gcc_dll\mswu -IC:\wxWidgets-3.1.0\lib\gcc_dll\mswu -IC:\TDM-GCC-64\bin -IC:\TDM-GCC-64 -c E:\WorkSpace\Code\TaskScheduler\main.cpp -o obj\Debug\main.o
E:\WorkSpace\Code\TaskScheduler\main.cpp:9:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(lib, "taskschd.lib")
 ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:10:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(lib, "comsupp.lib")
 ^
E:\WorkSpace\Code\TaskScheduler\main.cpp: In function 'int wmain()':
E:\WorkSpace\Code\TaskScheduler\main.cpp:22:50: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]
         printf("\nCoInitializeEx failed: %x", hr );
                                                  ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:40:56: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]
         printf("\nCoInitializeSecurity failed: %x", hr );
                                                        ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:47:5: error: 'ITaskService' was not declared in this scope
     ITaskService *pService = NULL;
     ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:47:19: error: 'pService' was not declared in this scope
     ITaskService *pService = NULL;
                   ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:48:28: error: 'CLSID_TaskScheduler' was not declared in this scope
     hr = CoCreateInstance( CLSID_TaskScheduler,
                            ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:51:28: error: 'IID_ITaskService' was not declared in this scope
                            IID_ITaskService,
                            ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:55:83: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]
           printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
                                                                                   ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:65:55: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]
         printf("ITaskService::Connect failed: %x", hr );
                                                       ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:72:5: error: 'IRunningTaskCollection' was not declared in this scope
     IRunningTaskCollection* pRunningTasks = NULL;
     ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:72:29: error: 'pRunningTasks' was not declared in this scope
     IRunningTaskCollection* pRunningTasks = NULL;
                             ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:73:36: error: 'TASK_ENUM_HIDDEN' was not declared in this scope
     hr = pService->GetRunningTasks(TASK_ENUM_HIDDEN, &pRunningTasks);
                                    ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:78:57: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]
         printf("Cannot get Root Folder pointer: %x", hr );
                                                         ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:94:55: warning: format '%d' expects argument of type 'int', but argument 2 has type 'LONG {aka long int}' [-Wformat=]
     printf("\nNumber of running tasks : %d", numTasks );
                                                       ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:96:5: error: 'TASK_STATE' was not declared in this scope
     TASK_STATE taskState;
     ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:100:9: error: 'IRunningTask' was not declared in this scope
         IRunningTask* pRunningTask = NULL;
         ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:100:23: error: 'pRunningTask' was not declared in this scope
         IRunningTask* pRunningTask = NULL;
                       ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:112:47: error: 'taskState' was not declared in this scope
                 hr = pRunningTask->get_State(&taskState);
                                               ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:116:78: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]
                     printf("\n\tCannot get the registered task state: %x", hr);
                                                                              ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:120:71: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'HRESULT {aka long int}' [-Wformat=]
                 printf("\nCannot get the registered task name: %x", hr);
                                                                       ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:126:84: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long int' [-Wformat=]
             printf("\nCannot get the registered task item at index=%d: %x", i+1, hr);
                                                                                    ^
E:\WorkSpace\Code\TaskScheduler\main.cpp:126:84: warning: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'HRESULT {aka long int}' [-Wformat=]
Process terminated with status 1 (0 minute(s), 8 second(s))
11 error(s), 12 warning(s) (0 minute(s), 8 second(s))
 

--- End quote ---

Navigation

[0] Message Index

[#] Next page

Go to full version