[ C / C++ ] — начинающим: задаем вопросы (архивная - 2015)

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by _Great_, 26 May 2007.

Thread Status:
Not open for further replies.
  1. Fl0dER

    Fl0dER New Member

    Joined:
    22 Dec 2008
    Messages:
    81
    Likes Received:
    3
    Reputations:
    0
    Заюзал , но ошибка всеравно выскакивает ...
     
  2. Fl0dER

    Fl0dER New Member

    Joined:
    22 Dec 2008
    Messages:
    81
    Likes Received:
    3
    Reputations:
    0
    Погуглил все примеры с этой функцией не на создание а на чтение файла .
     
  3. FoX's

    FoX's Дохлый

    Joined:
    26 Dec 2004
    Messages:
    169
    Likes Received:
    29
    Reputations:
    0
    попробуй еще SEM_FAILCRITICALERRORS
     
    1 person likes this.
  4. Fl0dER

    Fl0dER New Member

    Joined:
    22 Dec 2008
    Messages:
    81
    Likes Received:
    3
    Reputations:
    0
    Перед тем как вы написали , я уже нашол в гугле , но все равно спасибо !!!
     
  5. Fl0dER

    Fl0dER New Member

    Joined:
    22 Dec 2008
    Messages:
    81
    Likes Received:
    3
    Reputations:
    0
    Все эти хейдеры идут в комплекте с Dev C++ если я не ошибаюсь , сам пакет Dev C++ не очень большой , и вы можете все недостающие компоненты взять отуда .
     
  6. Fl0dER

    Fl0dER New Member

    Joined:
    22 Dec 2008
    Messages:
    81
    Likes Received:
    3
    Reputations:
    0
    У меня вопросик , как можно зделать проверку на активность интернета , а также рассоединения активного подключения ?
     
  7. POS_troi

    POS_troi Elder - Старейшина

    Joined:
    1 Dec 2006
    Messages:
    1,569
    Likes Received:
    466
    Reputations:
    108
    Для отключения первой найденной Ras-connection:

    Code:
    
    using System;
    using System.ComponentModel;
    using System.Runtime.InteropServices;
    namespace RAS
    {
        class Program
        {
            [DllImport("rasapi32.dll", SetLastError=true)]
            static extern uint RasHangUp(IntPtr hRasConn);
            const int MAX_PATH = 260;
            const int RAS_MaxDeviceType = 16;
            const int RAS_MaxEntryName = 256;
            const int RAS_MaxDeviceName = 128;        
            const int RAS_MaxPhoneNumber = 128;        
            [DllImport("RASAPI32", SetLastError = true, CharSet = CharSet.Auto)]
            static extern int RasEnumConnections(
                [In, Out] RASCONN[] lprasconn,
                ref int lpcb,
                ref int lpcConnections);
            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
            struct RASCONN
            {
                public int dwSize;
                public IntPtr hrasconn;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxEntryName + 1)]
                public string szEntryName;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceType + 1)]
                public string szDeviceType;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceName + 1)]
                public string szDeviceName;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)]
                public string szPhonebook;
                public int dwSubEntry;
            }
            static void Main(string[] args)
            {
                int conns = 0;
                RASCONN[] ras = new RASCONN[256];
                ras.Initialize();
                ras[0].dwSize = Marshal.SizeOf(typeof(RASCONN));
                int lr = ras[0].dwSize * ras.Length;         
                int ret = RasEnumConnections(ras, ref lr, ref conns);
                RasHangUp(ras[0].hrasconn);      
            }
        }
    }
    
    

    И соединение и разрыв.

    Code:
    
    
    using System;
    using System.Runtime.InteropServices;
    namespace ConsoleApplication1
    {
        class Program
        {
            [DllImport("Wininet.dll")]
            private static extern Int32 InternetDial(
                IntPtr hwndParent, 
                string lpszConnectoid, 
                Int32 dwFlags, 
                ref Int32 lpdwConnection, 
                Int32 dwReserved);
            const int MAX_PATH = 260;
            const int RAS_MaxEntryName = 256;
            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
            struct RASENTRYNAME
            {
                public int dwSize;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxEntryName + 1)]
                public string szEntryName;
                public int dwFlags;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH + 1)]
                public string szPhonebook;
            }
            [DllImport("rasapi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
            static extern uint RasEnumEntries(IntPtr reserved, IntPtr lpszPhonebook,
                [In, Out] RASENTRYNAME[] lprasentryname, ref int lpcb, ref int lpcEntries);
            [DllImport("wininet.dll", SetLastError = true)]
            [return: MarshalAs(UnmanagedType.Bool)]
            static extern bool InternetCloseHandle(
                IntPtr hInternet
                );
            [DllImport("wininet.dll", SetLastError = true)]
            static extern int InternetHangUp(
                int Connection, 
                int ReservedValue
                );
            
            static void Main(string[] args)
            {
                // все соединения
                //int cb = Marshal.SizeOf(typeof(RASENTRYNAME)), entries = 0;
                //RASENTRYNAME[] entryNames = new RASENTRYNAME[1];
                //entryNames[0].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME));
                ////Get entry number
                //uint nRet = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, entryNames, ref cb, ref entries);
                //if (entries == 0) return;
                //string[] _EntryNames = new string[entries];
                //entryNames = new RASENTRYNAME[entries];
                //for (int i = 0; i < entries; i++)
                //{
                //    entryNames[i].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME));
                //}
                //nRet = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, entryNames, ref cb, ref entries);
                //for (int i = 0; i < entries; i++)
                //{
                //    _EntryNames[i] = entryNames[i].szEntryName;
                //    Console.WriteLine(_EntryNames[i]);
                //}
                //Console.ReadKey();
                
                //return;
                
                /// вызов соединения по модему
                Int32 nConnection = new int();
                int nResult = InternetDial(
                    IntPtr.Zero,
                    "beeline",
                    (int)InternetDialFlags.INTERNET_DIAL_UNATTENDED, ref nConnection, 0);
                Console.WriteLine(nResult.ToString());
                Console.WriteLine(nConnection.ToString());
                Console.WriteLine("press a key");
                Console.ReadKey();
                Console.WriteLine(InternetHangUp(nConnection, 0));
                Console.WriteLine("should be closed");
            }
        }
        [Flags]
        enum InternetConnectionState : int
        {
            INTERNET_CONNECTION_MODEM = 0x1,
            INTERNET_CONNECTION_LAN = 0x2,
            INTERNET_CONNECTION_PROXY = 0x4,
            INTERNET_RAS_INSTALLED = 0x10,
            INTERNET_CONNECTION_OFFLINE = 0x20,
            INTERNET_CONNECTION_CONFIGURED = 0x40
        }
        
        [Flags]
        enum InternetDialFlags
        {
            INTERNET_DIAL_FORCE_PROMPT = 0x2000,
            INTERNET_DIAL_SHOW_OFFLINE = 0x4000,
            INTERNET_DIAL_UNATTENDED = 0x8000
        }
    }
    
    
    по теме

    http://msdn.microsoft.com/en-us/library/aa365943.aspx
    http://msdn.microsoft.com/en-us/library/aa366842(VS.85).aspx
    http://msdn.microsoft.com/en-us/library/aa366836(VS.85).aspx
     
    #2307 POS_troi, 10 Feb 2009
    Last edited: 10 Feb 2009
  8. St0nX

    St0nX Elder - Старейшина

    Joined:
    19 May 2007
    Messages:
    257
    Likes Received:
    46
    Reputations:
    0
    InternetGetConnectedState - для проверки попробуй эту.
     
  9. Fl0dER

    Fl0dER New Member

    Joined:
    22 Dec 2008
    Messages:
    81
    Likes Received:
    3
    Reputations:
    0
    Не как немогу заюзать , почти все примеры работают не коректо , так как зачитывают LAN соединения ...

    Как можно узнать подключен компьютер к сети интернет , чтобы подключения LAN'a не считывалось ?


    некак не разберусь с кодом , мнебы только проверку на активность интернета =/
     
    #2309 Fl0dER, 10 Feb 2009
    Last edited: 10 Feb 2009
  10. St0nX

    St0nX Elder - Старейшина

    Joined:
    19 May 2007
    Messages:
    257
    Likes Received:
    46
    Reputations:
    0
    ну не знаю у меня для подключение к интернету используется PPPoE соединение и таким кодом

    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <wininet.h>
    
    #pragma comment(lib,"wininet.lib");
    
    int main()
    {
    DWORD dw;
    if (InternetGetConnectedState(&dw,0))
    {
    	 if ((dw & INTERNET_CONNECTION_MODEM)==INTERNET_CONNECTION_MODEM)
    	 {
    printf("Good");
    	 }
    }
    return 0;
    }

    Все проверяется как надо. Если есть возможность проверь с разными видами подкл.А вообще если ничего не подходит то просто пробуй делать коннект к какому нибудь интернет серваку если не выходит значит нету соединения или какие то иные проблемы.
     
    #2310 St0nX, 10 Feb 2009
    Last edited: 10 Feb 2009
  11. or1

    or1 Banned

    Joined:
    7 Sep 2008
    Messages:
    36
    Likes Received:
    4
    Reputations:
    0
    //#include <cstdlib>
    #include <iostream>
    #include <fstream>

    using namespace std;

    int main(int argc, char *argv[])
    {
    ofstream file;
    file.open("hello_or1.txt",ios::app);
    file.close();
    system("PAUSE");
    return EXIT_SUCCESS;
    }


    как тут можно функцию прописать xcopy не отрываясь и типо чтоб на мой хостинг отослал этот файл hello_or1.txt ,значит так открываем, копируем и отсылаем это мне надо как можно тут сделать ?
    мож для ссылки вот такую функцию добавить ShellExecute(NULL, "open", "http://www.xosting.ru/login.php/",
    NULL, NULL, SW_SHOWNORMAL);просто не могу все в месте сложить,,если что не правильно то подскажите плз.
     
    #2311 or1, 11 Feb 2009
    Last edited: 11 Feb 2009
  12. n4e/\@

    n4e/\@ Elder - Старейшина

    Joined:
    6 May 2008
    Messages:
    138
    Likes Received:
    17
    Reputations:
    0
    Отсылай через сокеты или curl, еще вроде есть winhttp/wininet, в последнем это вобще будет одна строка.
     
  13. Fl0dER

    Fl0dER New Member

    Joined:
    22 Dec 2008
    Messages:
    81
    Likes Received:
    3
    Reputations:
    0
    При попытки союзать в VC++ wininet.h


    Code:
    1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(58) : error C2146: syntax error : missing ';' before identifier 'HINTERNET' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(58) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(58) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(59) : error C2143: syntax error : missing ';' before '*' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(59) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(59) : error C2378: 'HINTERNET' : redefinition; symbol cannot be overloaded with a typedef 1>        C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(58) : see declaration of 'HINTERNET' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(59) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(61) : error C2146: syntax error : missing ';' before identifier 'INTERNET_PORT' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(61) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(61) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(62) : error C2143: syntax error : missing ';' before '*' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(62) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(62) : error C2378: 'INTERNET_PORT' : redefinition; symbol cannot be overloaded with a typedef 1>        C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(61) : see declaration of 'INTERNET_PORT' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(62) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(311) : error C2146: syntax error : missing ';' before identifier 'dwResult' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(311) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(311) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(317) : error C2146: syntax error : missing ';' before identifier 'dwError' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(317) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(317) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(326) : error C2146: syntax error : missing ';' before identifier 'Socket' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(326) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(326) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(327) : error C2146: syntax error : missing ';' before identifier 'SourcePort' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(327) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(327) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(328) : error C2146: syntax error : missing ';' before identifier 'DestPort' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(328) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(328) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(329) : error C2146: syntax error : missing ';' before identifier 'Flags' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(329) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(329) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(353) : error C2146: syntax error : missing ';' before identifier 'dwAccessType' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(353) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(353) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(359) : error C2146: syntax error : missing ';' before identifier 'lpszProxy' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(359) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(359) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(365) : error C2146: syntax error : missing ';' before identifier 'lpszProxyBypass' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(365) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(365) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(377) : error C2146: syntax error : missing ';' before identifier 'dwOption' 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(377) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(377) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\wininet.h(379) : error C2146: syntax error : missing ';' before identifier 'dwValue' .....................................

    Как я понял из за того что wininet на C , где в настройках проэкта подправить чтобы VC++ мог заюзать хейдер C ?




    Все разобрался ;)
     
    #2313 Fl0dER, 11 Feb 2009
    Last edited: 11 Feb 2009
  14. Fl0dER

    Fl0dER New Member

    Joined:
    22 Dec 2008
    Messages:
    81
    Likes Received:
    3
    Reputations:
    0
    Недавно форуме видел код коменты линкера VC++ с помощью него уменьшается вес программ из 32кб консольной проги в 0.5 кб , вот только не помню где ... Мож кто знает ?
     
  15. St0nX

    St0nX Elder - Старейшина

    Joined:
    19 May 2007
    Messages:
    257
    Likes Received:
    46
    Reputations:
    0
    _ttp://www.cyberguru.ru/programming/win32/small-win32-applications.html
     
  16. BlackSilver

    BlackSilver New Member

    Joined:
    30 Jan 2009
    Messages:
    28
    Likes Received:
    4
    Reputations:
    0
    Как на WinAPI замутить TreeView с несколькими колонками?
     
  17. or1

    or1 Banned

    Joined:
    7 Sep 2008
    Messages:
    36
    Likes Received:
    4
    Reputations:
    0
    ws2_32.lib плз кто подскажет где скачать можно
     
  18. St0nX

    St0nX Elder - Старейшина

    Joined:
    19 May 2007
    Messages:
    257
    Likes Received:
    46
    Reputations:
    0
    скачай dev c++ или студию. отдельно они не валяются.
     
  19. POS_troi

    POS_troi Elder - Старейшина

    Joined:
    1 Dec 2006
    Messages:
    1,569
    Likes Received:
    466
    Reputations:
    108
    http://rapidshare.com/files/196838894/ws2_32.lib.html
     
  20. Fl0dER

    Fl0dER New Member

    Joined:
    22 Dec 2008
    Messages:
    81
    Likes Received:
    3
    Reputations:
    0
    Хотел заюзать str.find в BCB++ но вот какая трабла

    сам код
    Code:
    String str = "superpuperdata";
    String str2 = ("data");
    size_t found;
    
    
    found=str.find(str2);
    if (found!=string::npos)
    {
    }


    Ошибка
    Code:
    [BCC32 Error] Unit1.cpp(48): E2316 'find' is not a member of 'AnsiString'
     
Thread Status:
Not open for further replies.