那位大侠能告诉我
     我想调用某一文件夹下的可执行文件 该怎么写呢?
 我先谢谢了.

解决方案 »

  1.   

    WinExec("C:\\a.exe",SW_SHOW);
    也可以用CreateProcess()
      

  2.   

    BOOL CreateProcess(
      LPCTSTR lpApplicationName,
      LPTSTR lpCommandLine,
      LPSECURITY_ATTRIBUTES lpProcessAttributes,
      LPSECURITY_ATTRIBUTES lpThreadAttributes,
      BOOL bInheritHandles,
      DWORD dwCreationFlags,
      LPVOID lpEnvironment,
      LPCTSTR lpCurrentDirectory,
      LPSTARTUPINFO lpStartupInfo,
      LPPROCESS_INFORMATION lpProcessInformation
    );
      

  3.   

    WinExec()适用16位windows系统
    32位的应用程序应该使用CreateProcess
      

  4.   

    // FILE: pktcap.cpp
    #include <pcap.h>
    #include <wtypes.h>// Struct of ethernet II header
    typedef struct
    {
    UCHAR DestMac[6];
    UCHAR SrcMac[6];
    UCHAR Etype[2];
    }ETHHEADER, *PETHHEADER;#define ETHHEADERSIZE 14HANDLE hStdOut;// dispatcher routine prototype
    void dispatcher_handler(u_char*, const pcap_pkthdr*, const u_char*);void main(void)
    {
    char ebuf[PCAP_ERRBUF_SIZE]; // error buffer
    char *adapter; // adapter name
    pcap_t* fp; // packet capture descriptor hStdOut = ::GetStdHandle(STD_OUTPUT_HANDLE);

    // Step 1: Lookup the adapter
    adapter=(char*)pcap_lookupdev(ebuf);
    if(adapter == NULL)
    {
    printf(TEXT("PCAP error:%s\n"), ebuf);
    return;
    } // Step 2: Open the adapter
    // Note: the adapter may not proper adapter!!
    fp = pcap_open_live(adapter, 2000, 1, 20, ebuf);
    if(fp == NULL)
    {
    printf(TEXT("PCAP error:%s\n"), ebuf);
    return;
    } // Step 3: Check the datalink.
    if(pcap_datalink(fp) != DLT_EN10MB)
    {
    printf("Not Ethernet 10MB adapter!\n");
    pcap_close(fp);
    return;
    } // Step 4: Start capturing.
    pcap_loop(fp, 0, dispatcher_handler, NULL); // Step 5: Close the adapter.
      pcap_close(fp);
    }#define ATTR_NORMAL (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
    #define ATTR_VALUE (FOREGROUND_GREEN)
    #define ATTR_DATA (FOREGROUND_RED | FOREGROUND_BLUE)// callback routine called by libpcap for every incoming packet
    void dispatcher_handler(u_char *,const struct pcap_pkthdr *header, const u_char *pkt_data)
    {
    PETHHEADER eth_header = (PETHHEADER)pkt_data;
    ::SetConsoleTextAttribute(hStdOut, ATTR_NORMAL);
    printf("\r\nCaptured time:");
    ::SetConsoleTextAttribute(hStdOut, ATTR_VALUE);
    printf("%ld:%ld",header->ts.tv_sec, header->ts.tv_usec);
    ::SetConsoleTextAttribute(hStdOut, ATTR_NORMAL);
    printf("\r\nPacket Length:");
    ::SetConsoleTextAttribute(hStdOut, ATTR_VALUE);
    printf("%ld",header->len); if (header->len >= ETHHEADERSIZE)
    {
    ::SetConsoleTextAttribute(hStdOut, ATTR_NORMAL);
    printf("\r\nDestination MAC:");
    ::SetConsoleTextAttribute(hStdOut, ATTR_VALUE);
    printf("%02X-%02X-%02X-%02X-%02X-%02X", eth_header->DestMac[0],
    eth_header->DestMac[1], eth_header->DestMac[2], eth_header->DestMac[3],
    eth_header->DestMac[4], eth_header->DestMac[5]); ::SetConsoleTextAttribute(hStdOut, ATTR_NORMAL);
    printf("\r\nSource MAC:");
    ::SetConsoleTextAttribute(hStdOut, ATTR_VALUE);
    printf("%02X-%02X-%02X-%02X-%02X-%02X", eth_header->SrcMac[0],
    eth_header->SrcMac[1], eth_header->SrcMac[2], eth_header->SrcMac[3],
    eth_header->SrcMac[4], eth_header->SrcMac[5]); ::SetConsoleTextAttribute(hStdOut, ATTR_NORMAL);
    printf("\r\nProtocol type:");
    ::SetConsoleTextAttribute(hStdOut, ATTR_VALUE);
    printf("%02X%02X", eth_header->Etype[0], eth_header->Etype[1]);
    }

    ::SetConsoleTextAttribute(hStdOut, ATTR_DATA);
    printf("\r\n");
    u_char *p = (u_char *)pkt_data;
    for(int i = 0; i < (int)header->len; i++)
    {
    printf("%02X ", *p++);
    if( (i + 1) % 16 == 0)
    printf("\n");
    }
    }
      

  5.   

    以上是我调用程序的代码
    是 Win32 Console Application 生成可执行文件
      

  6.   

    可以通过
    以为是调用了WinpCap库来捕获数据包
    要在系统中加载wpcap.lib文件就行了
    我已经调试通过了
    库文件可在
    http://winpcap.polito.it上下载
      

  7.   

    在Project->settings中设置一下,在tools->options->Directories里面把include
    files ,Library files 路径加入
    就可以了
    运行后是捕获以太网数据帧的程序
    我想将其假如到我的另一个程序中
      

  8.   

    那你怎么调用生成的这个可执行程序的呢?
    用WinExec 还是CreateProcess()
    这两个函数的参数又是怎么写的?
      

  9.   

    我用WinExec("\\pktcap.exe",SW_SHOW);
    没报错
    但是没法运行
      

  10.   

    你把代码改成WinExec("pktcap.exe",SW_SHOW);
      

  11.   

    WinExec,如果他的第一个参数不正确,是不会报错的,
    如果WinExec成功执行,他的返回值大于31
      

  12.   

    你能给我你的联系方式吗
    我的信箱是 [email protected]
      

  13.   

    如果是在应用程序当前的文件夹下,.exe 可省略不写。