Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Системное программирование и WinAPI > Запуск стороннего приложения через WINAPI


Автор: Saman 9.12.2009, 08:25
Есть некая программа, которая читает инструкцию из .cmd (в моём случае, это "start.cmd") файла и потом её запускает. (запускает JAVA-программу, например)

её код:

Код

#include <stdio.h>
#include <stdlib.h>
#include <shellapi.h> 
int main(int argc, char **argv){
    FILE *f;
    f=fopen("start.cmd","r"); 
    char s[256];
    while ( !feof(f)){
    
        fgets(s,256,f); 
    
    }
    ShellExecute(NULL, "open", s, NULL, NULL, "", SW_SHOWNORMAL);
    return 0;
}


При компилляции командой 
Код

g++ main.cpp -o executor


выдаётся море ошибок (насколько я понимаю, связанных с shellapi.h)

Код

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:142: error: `WORD' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:143: error: `WORD' does not name a type
cpp:3:
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:146: error: `DWORD' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:147: error: `HWND' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:148: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:149: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:150: error: `RECT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:151: error: `LPARAM' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:153: error: expected constructor, destru
fore '(' token
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:156: error: `DWORD' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:157: error: `HWND' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:158: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:159: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:160: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:161: error: `HICON' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:174: error: `CHAR' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:185: error: `DWORD' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:186: error: `HWND' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:187: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:188: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:189: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:190: error: `HICON' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:203: error: `WCHAR' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:214: error: `DWORD' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:215: error: `ULONG' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:216: error: `HWND' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:217: error: `LPCSTR' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:218: error: `LPCSTR' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:219: error: `LPCSTR' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:220: error: `LPCSTR' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:222: error: `HINSTANCE' does not name a

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:223: error: `PVOID' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:224: error: `LPCSTR' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:225: error: `HKEY' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:226: error: `DWORD' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:227: error: `HANDLE' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:228: error: `HANDLE' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:231: error: `DWORD' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:232: error: `ULONG' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:233: error: `HWND' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:234: error: `LPCWSTR' does not name a ty

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:235: error: `LPCWSTR' does not name a ty

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:236: error: `LPCWSTR' does not name a ty

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:237: error: `LPCWSTR' does not name a ty

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:239: error: `HINSTANCE' does not name a

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:240: error: `PVOID' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:241: error: `LPCWSTR' does not name a ty

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:242: error: `HKEY' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:243: error: `DWORD' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:244: error: `HANDLE' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:245: error: `HANDLE' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:248: error: `HWND' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:249: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:250: error: `LPCSTR' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:251: error: `LPCSTR' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:252: error: `FILEOP_FLAGS' does not name

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:253: error: `BOOL' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:254: error: `PVOID' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:255: error: `LPCSTR' does not name a typ

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:258: error: `HWND' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:259: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:260: error: `LPCWSTR' does not name a ty

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:261: error: `LPCWSTR' does not name a ty

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:262: error: `FILEOP_FLAGS' does not name

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:263: error: `BOOL' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:264: error: `PVOID' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:265: error: `LPCWSTR' does not name a ty

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:268: error: `HICON' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:270: error: `DWORD' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:271: error: `CHAR' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:272: error: `CHAR' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:275: error: `HICON' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:277: error: `DWORD' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:278: error: `WCHAR' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:279: error: `WCHAR' does not name a type

lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:282: error: `DWORD' does not name a type

cpp:3:
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:288: error: expected constructor, destru
fore '*' token
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:289: error: `WINAPI' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:290: error: `WINAPI' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:291: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:292: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:293: error: `BOOL' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:294: error: `HICON' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:295: error: `HICON' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:296: error: `HICON' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:297: error: `HICON' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:298: error: `HICON' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:299: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:300: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:301: error: `HINSTANCE' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:302: error: `HINSTANCE' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:303: error: `UINT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:304: error: `BOOL' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:305: error: `BOOL' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:306: error: `WINAPI' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:307: error: `WINAPI' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:308: error: `HINSTANCE' does not name a  type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:309: error: `HINSTANCE' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:310: error: `BOOL' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:311: error: `BOOL' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:312: error: `WINAPI' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:313: error: `WINAPI' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:314: error: `WINAPI' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:315: error: `DWORD' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:316: error: `DWORD' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:317: error: `HRESULT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:318: error: `HRESULT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:319: error: `HRESULT' does not name a type
lib/gcc/mingw32/3.4.5/../../../../include/shellapi.h:320: error: `HRESULT' does not name a type


main.cpp: In function `int main(int, char**)':
main.cpp:15: error: `SW_SHOWNORMAL' was not declared in this scope
main.cpp:15: error: `ShellExecuteA' was not declared in this scope


как решить эту проблему?

Автор: smoke_man 9.12.2009, 08:35
Попробуй так:
Код

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <shellapi.h> 
int main(int argc, char **argv){
    FILE *f;
    f=fopen("start.cmd","r"); 
    char s[256];
    while ( !feof(f)){
    
        fgets(s,256,f); 
    
    }
    ShellExecute(NULL, "open", &s[0], NULL, NULL, SW_SHOWNORMAL);
    return 0;
}

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)