mustelus
Участник
Offline
|
|
« : 19-11-2009 00:06 » |
|
Привет всем... У меня такая проблема: скачал клас c для работы с COM портом (я так подозреваю , это клас c MFC) Я сделал приложение в Windows Forms и пытаюсь в это приложение экспортировать этот клас c следующим образом: extern "C" class __declspec (dllexport) SerialGate { public: enum IN_LINES_NAME {CTS, DSR, RING, RLSD}; enum OUT_LINES_NAME {DTR, RTS}; SerialGate(); ~SerialGate(); bool Open(int port, int baud); int Send(char* buff, int szBuff); int Recv(char* buff, int szBuff); void SetLine(OUT_LINES_NAME ln, bool state); bool GetLine(IN_LINES_NAME ln); void GetPortsInfo(PortInfo* pi); void Close(); void Clean(); private: HANDLE m_hFile; bool state; }; и компилятор по этому поводу ругае тся... Подскажите синтаксис экспорта/импорта классов, функций из DLL, искал на MSDN , так по поводу импорта в FORMах ничего нет (или плохо искал)....
|
|
« Последнее редактирование: 30-11-2009 10:13 от Джон »
|
Записан
|
|
|
|
Алексей++
глобальный и пушистый
Глобальный модератор
Offline
Сообщений: 13
|
|
« Ответ #1 : 19-11-2009 06:23 » |
|
А текст ругани-то покажи ?
Но это на 120% не класс MFC (и вообще никакого намёка нет на это)
|
|
« Последнее редактирование: 19-11-2009 08:00 от Sel »
|
Записан
|
|
|
|
Вад
|
|
« Ответ #2 : 19-11-2009 06:26 » |
|
Есть всё в MSDN. To export all of the public data members and member functions in a class, the keyword must appear to the left of the class name as follows: class __declspec(dllexport) CExampleExport : public CObject { ... class definition ... }; А extern "C" - это из другой оперы. Это для экспорта функций, доступного для сишной линковки.
|
|
« Последнее редактирование: 19-11-2009 06:31 от Вад »
|
Записан
|
|
|
|
mustelus
Участник
Offline
|
|
« Ответ #3 : 20-11-2009 09:37 » |
|
А текст ругани-то покажи ?
Но это на 120% не класс MFC (и вообще никакого намёка нет на это)
Error 4 error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe c:\project_for_vs\pravda\pravda\SerialGate.h 28 pravda Error 5 error C3395: 'SerialGate::SerialGate' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\project_for_vs\pravda\pravda\SerialGate.h 35 pravda Error 6 error C3395: 'SerialGate::~SerialGate' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\project_for_vs\pravda\pravda\SerialGate.h 36 pravda Error 7 error C3395: 'SerialGate::Open' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\project_for_vs\pravda\pravda\SerialGate.h 38 pravda Error 8 error C3395: 'SerialGate::Send' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\project_for_vs\pravda\pravda\SerialGate.h 39 pravda Error 9 error C3395: 'SerialGate::Recv' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\project_for_vs\pravda\pravda\SerialGate.h 40 pravda Error 10 error C3395: 'SerialGate::SetLine' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\project_for_vs\pravda\pravda\SerialGate.h 41 pravda Error 11 error C3395: 'SerialGate::GetLine' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\project_for_vs\pravda\pravda\SerialGate.h 42 pravda Error 12 error C3395: 'SerialGate::GetPortsInfo' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\project_for_vs\pravda\pravda\SerialGate.h 43 pravda Error 13 error C3395: 'SerialGate::Close' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\project_for_vs\pravda\pravda\SerialGate.h 44 pravda Error 14 error C3395: 'SerialGate::Clean' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\project_for_vs\pravda\pravda\SerialGate.h 45 pravda Error 15 error C3395: 'SerialGate::SerialGate' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\project_for_vs\pravda\pravda\SerialGate.h 50 pravda Error 16 error C3395: 'SerialGate::operator =' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\project_for_vs\pravda\pravda\SerialGate.h 50 pravda Error 17 error C2065: 'sg' : undeclared identifier c:\project_for_VS\pravda\pravda\pravda.cpp 17 pravda Error 18 error C2228: left of '.Open' must have class/struct/union c:\project_for_VS\pravda\pravda\pravda.cpp 17 pravda
в общем на каждый символ, каждую функцию класа и сам клас....
|
|
« Последнее редактирование: 30-11-2009 10:14 от Джон »
|
Записан
|
|
|
|
Вад
|
|
« Ответ #4 : 20-11-2009 10:12 » |
|
Так это managed C++, .NET? Я думал, нужно обычный код экспортировать и подхватить в .NET. Потому что этот тип вызова (__clrcall), судя по MSDN, используется при компиляции с CLR. Тогда и экспорт в dll должен выполняться средствами .NET, наверное.
P.S. Я не спец по экспорту в .NET, но что, если вообще не указывать спецификаторов для экспорта в managed-коде? По-моему, такие классы и так должны быть видны при импорте этой библиотеки.
|
|
« Последнее редактирование: 20-11-2009 10:32 от Вад »
|
Записан
|
|
|
|
mustelus
Участник
Offline
|
|
« Ответ #5 : 20-11-2009 10:51 » |
|
Работаю в VS 2008 (windows forms), не в NET, но это почти одно и то же... Попробую так "взять эти класы". но что, если вообще не указывать спецификаторов для экспорта в managed-коде? По-моему, такие классы и так должны быть видны при импорте этой библиотеки.
Не работает и так, блин, приде тся искать средства VS....
|
|
« Последнее редактирование: 22-11-2009 20:07 от Sel »
|
Записан
|
|
|
|
Джон
просто
Администратор
Offline
Пол:
|
|
« Ответ #6 : 20-11-2009 11:04 » |
|
А чем обусловлен такой коктейль? Если тебе надо использовать COM порт на уровне API, то делай приложение в API или MFC. Если тебе необходимо .NET приложение, то пользуйся средствами .NET для связи с COM портом. Какие проблемы?
|
|
|
Записан
|
Я вам что? Дурак? По выходным и праздникам на работе работать. По выходным и праздникам я работаю дома. "Just because the language allows you to do something does not mean that it’s the correct thing to do." Trey Nash "Physics is like sex: sure, it may give some practical results, but that's not why we do it." Richard P. Feynman "All science is either physics or stamp collecting." Ernest Rutherford "Wer will, findet Wege, wer nicht will, findet Gründe."
|
|
|
mustelus
Участник
Offline
|
|
« Ответ #7 : 20-11-2009 23:26 » |
|
Конечно может я что то не допонимаю но всеже разьясню по своему... В MFC нужно проделать много работы например нарисовать всякие стандартные элементы, а в Windows Forms попроще, только остаеться сделать что куда выводить и т.д.
|
|
|
Записан
|
|
|
|
Алексей++
глобальный и пушистый
Глобальный модератор
Offline
Сообщений: 13
|
|
« Ответ #8 : 20-11-2009 23:29 » |
|
mustelus, стандартные элементы в MFC не надо рисовать - они там есть уже )
|
|
|
Записан
|
|
|
|
Джон
просто
Администратор
Offline
Пол:
|
|
« Ответ #9 : 20-11-2009 23:39 » |
|
Windows Forms попроще Согласен, но почему ты тогда используешь некий сторонний класс для работы с СОМ-портом? Чем тебя в этом плане .NET не устраивает?
|
|
|
Записан
|
Я вам что? Дурак? По выходным и праздникам на работе работать. По выходным и праздникам я работаю дома. "Just because the language allows you to do something does not mean that it’s the correct thing to do." Trey Nash "Physics is like sex: sure, it may give some practical results, but that's not why we do it." Richard P. Feynman "All science is either physics or stamp collecting." Ernest Rutherford "Wer will, findet Wege, wer nicht will, findet Gründe."
|
|
|
Вад
|
|
« Ответ #10 : 21-11-2009 18:34 » |
|
Так, стоп, до меня, кажется, дошло, в чём корень всех зол. Дело в том, что mustelus скачал класc для работы с COM портом и этот класс ни разу не является классом для managed c++, а написан на вполне обычном. Думаю, отсюда могут расти уши с проблемами компиляции. Возможно, такие проблемы обходятся чем-нибудь типа #pragma unmanaged. А может, и нет BTW, весь бардак - от попыток взять и воткнуть обычный visual c++-ный код в C++ .NET.
|
|
|
Записан
|
|
|
|
Джон
просто
Администратор
Offline
Пол:
|
|
« Ответ #11 : 22-11-2009 05:52 » |
|
Ну да. Это-то я и не могу понять, нафига оно нужно?
|
|
|
Записан
|
Я вам что? Дурак? По выходным и праздникам на работе работать. По выходным и праздникам я работаю дома. "Just because the language allows you to do something does not mean that it’s the correct thing to do." Trey Nash "Physics is like sex: sure, it may give some practical results, but that's not why we do it." Richard P. Feynman "All science is either physics or stamp collecting." Ernest Rutherford "Wer will, findet Wege, wer nicht will, findet Gründe."
|
|
|
mustelus
Участник
Offline
|
|
« Ответ #12 : 22-11-2009 20:06 » |
|
Кажись вы настоящие профи..... Действительно, я использую "самопальный" класс, и пытаюсь его воткнуть в проект.... А не использую "родной" клас нета т.к. не знал что таковой существует (а кстати, етот клас с виртуальными COM портами нормально работает? ?)
|
|
|
Записан
|
|
|
|
Алексей++
глобальный и пушистый
Глобальный модератор
Offline
Сообщений: 13
|
|
« Ответ #13 : 22-11-2009 20:08 » |
|
mustelus, если драйвер эмулятора не кривой, то это будет самый обычный порт с точки зрения для открывающего COM порт В общем, работай спокойно и с виртуальными
|
|
|
Записан
|
|
|
|
|
Вад
|
|
« Ответ #15 : 23-11-2009 20:25 » |
|
|
|
|
Записан
|
|
|
|
|
Джон
просто
Администратор
Offline
Пол:
|
|
« Ответ #17 : 24-11-2009 07:15 » |
|
mustelus, ты что-нить про MSDN или google слышал? Советую с этого начать, они несут разумное, вечное, доброе.
|
|
|
Записан
|
Я вам что? Дурак? По выходным и праздникам на работе работать. По выходным и праздникам я работаю дома. "Just because the language allows you to do something does not mean that it’s the correct thing to do." Trey Nash "Physics is like sex: sure, it may give some practical results, but that's not why we do it." Richard P. Feynman "All science is either physics or stamp collecting." Ernest Rutherford "Wer will, findet Wege, wer nicht will, findet Gründe."
|
|
|
mustelus
Участник
Offline
|
|
« Ответ #18 : 25-11-2009 18:42 » |
|
Что за чертовщина: #using <System.DLL> #include "stdafx.h" #include "Form1.h" #include <windows.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <time.h> #include "devioctl.h" #include <setupapi.h> #include <basetyps.h> #include "BulkUsr.h" #include "usbdi.h" #define NOISY(_x_) printf _x_ ; using namespace Prilogenie; char inPipe[32] = "PIPE00"; // pipe name for bulk input pipe on our test board имя канала для массовой входа канала char outPipe[32] = "PIPE01"; // pipe name for bulk output pipe on our test board имя канала выходного char completeDeviceName[256] = ""; //generated from the GUID registered by the driver itself
BOOL fDumpUsbConfig = FALSE; // flags set in response to console command line switches BOOL fDumpReadData = FALSE; BOOL fRead = FALSE; BOOL fWrite = FALSE;
int gDebugLevel = 1; // higher == more verbose, default is 1, 0 turns off all
ULONG IterationCount = 1; //count of iterations of the test we are to perform int WriteLen = 0; // #bytes to write int ReadLen = 0;
[STAThreadAttribute]
int main(array<System::String ^> ^args) { // Enabling Windows XP visual effects before any controls are created Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it Application::Run(gcnew Form1());
_serialPort.Open(); _serialPort.Read(array<unsigned char>^ buffer, int offset, int count);
return 0; };
И мне в ответ на build: Error 3 error C2065: '_serialPort' : undeclared identifier c:\project_for_VS\Prilogenie\Prilogenie\Prilogenie.cpp 45 Prilogenie Error 4 error C2228: left of '.Open' must have class/struct/union c:\project_for_VS\Prilogenie\Prilogenie\Prilogenie.cpp 45 Prilogenie Error 5 error C2065: '_serialPort' : undeclared identifier c:\project_for_VS\Prilogenie\Prilogenie\Prilogenie.cpp 46 Prilogenie Error 6 error C2228: left of '.Read' must have class/struct/union c:\project_for_VS\Prilogenie\Prilogenie\Prilogenie.cpp 46 Prilogenie Error 7 error C2065: 'buffer' : undeclared identifier c:\project_for_VS\Prilogenie\Prilogenie\Prilogenie.cpp 46 Prilogenie Error 8 error C2275: 'cli::array<Type>' : illegal use of this type as an expression c:\project_for_VS\Prilogenie\Prilogenie\Prilogenie.cpp 46 Prilogenie Error 9 error C2062: type 'int' unexpected c:\project_for_VS\Prilogenie\Prilogenie\Prilogenie.cpp 46 Prilogenie
Что еще включить надо та? ?
|
|
« Последнее редактирование: 30-11-2009 10:15 от Джон »
|
Записан
|
|
|
|
Вад
|
|
« Ответ #19 : 25-11-2009 18:47 » |
|
А где объявляется переменная _serialPort?
|
|
|
Записан
|
|
|
|
mustelus
Участник
Offline
|
|
« Ответ #20 : 25-11-2009 19:17 » |
|
В #using <System.DLL> на сколько я понял....
|
|
|
Записан
|
|
|
|
Вад
|
|
« Ответ #21 : 25-11-2009 19:43 » |
|
С чего вдруг? Ты должен сам объявить переменную типа SerialPort и проинициализировать её (задав имя/путь своего порта, вообще говоря)
|
|
|
Записан
|
|
|
|
mustelus
Участник
Offline
|
|
« Ответ #22 : 26-11-2009 16:12 » |
|
Ну предположим понял дальнейший ход, а примера никокого нет (COM с использование в VS 2008)....
|
|
|
Записан
|
|
|
|
Джон
просто
Администратор
Offline
Пол:
|
|
« Ответ #23 : 26-11-2009 22:43 » |
|
А какая разнца в кАкой студии его испльзовать? Для твоих целей любая студия подойдёт. Предположим у тебя не 2008 студия, а ... любая другая - твоей душе угодная. Чтобы ты сделал? Раз ты дальнейший ход понял, то развивай мысль, а уж загнать её в 2008 студию поможем, было бы что загонять.
|
|
|
Записан
|
Я вам что? Дурак? По выходным и праздникам на работе работать. По выходным и праздникам я работаю дома. "Just because the language allows you to do something does not mean that it’s the correct thing to do." Trey Nash "Physics is like sex: sure, it may give some practical results, but that's not why we do it." Richard P. Feynman "All science is either physics or stamp collecting." Ernest Rutherford "Wer will, findet Wege, wer nicht will, findet Gründe."
|
|
|
mustelus
Участник
Offline
|
|
« Ответ #24 : 28-11-2009 21:58 » |
|
А вот смотрите, что сдесь еще включить, что обьявить что б ругаться компилятор перестал #using <System.DLL> #include "stdafx.h" #include "Form1.h" #include <windows.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <time.h> #include "devioctl.h" #include <setupapi.h> #include <basetyps.h> #include "BulkUsr.h" #include "usbdi.h"
using namespace Prilogenie; using namespace System; using namespace System::Security; using namespace System::Security::Permissions; using namespace System::Runtime::InteropServices;
[STAThreadAttribute]
int main(array<System::String ^> ^args) { //// Enabling Windows XP visual effects before any controls are created Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); //// Create the main window and run it Application::Run(gcnew Form1()); ////
static bool _continue; static SerialPort _serialPort;
string name; string message; StringComparer stringComparer = StringComparer.OrdinalIgnoreCase; Thread readThread = new Thread(Read);
// Create a new SerialPort object with default settings. _serialPort = new SerialPort();
// Allow the user to set the appropriate properties. _serialPort.PortName = SetPortName(_serialPort.PortName); _serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate); _serialPort.Parity = SetPortParity(_serialPort.Parity); _serialPort.DataBits = SetPortDataBits(_serialPort.DataBits); _serialPort.StopBits = SetPortStopBits(_serialPort.StopBits); _serialPort.Handshake = SetPortHandshake(_serialPort.Handshake);
// Set the read/write timeouts _serialPort.ReadTimeout = 500; _serialPort.WriteTimeout = 500;
_serialPort.Open(); _continue = true; readThread.Start();
Console.Write("Name: "); name = Console.ReadLine();
Console.WriteLine("Type QUIT to exit");
while (_continue) { message = Console.ReadLine();
if (stringComparer.Equals("quit", message)) { _continue = false; } else { _serialPort.WriteLine( String.Format("<{0}>: {1}", name, message) ); } }
readThread.Join(); _serialPort.Close();
};
Обьявил же обьект класса....
|
|
« Последнее редактирование: 30-11-2009 10:13 от Джон »
|
Записан
|
|
|
|
Вад
|
|
« Ответ #25 : 28-11-2009 22:08 » |
|
А почему именно static SerialPort? И - ругается случайно не на вот этот кусок кода: // Allow the user to set the appropriate properties. _serialPort.PortName = SetPortName(_serialPort.PortName); _serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate); _serialPort.Parity = SetPortParity(_serialPort.Parity); _serialPort.DataBits = SetPortDataBits(_serialPort.DataBits); _serialPort.StopBits = SetPortStopBits(_serialPort.StopBits); _serialPort.Handshake = SetPortHandshake(_serialPort.Handshake);
? Откуда ты его скопировал? И зачем он, как ты думаешь, он нужен?
|
|
|
Записан
|
|
|
|
mustelus
Участник
Offline
|
|
« Ответ #26 : 29-11-2009 09:31 » |
|
Пример скачал из MSDN (правда он там на C#), ругаеться почти на все, начиная от обьявления SerialPort _serialPort; (типо необьявленная переменная).... Я так понял что я не включил библиотеку с етим класом, и как ето сделать не понимаю...
|
|
|
Записан
|
|
|
|
Вад
|
|
« Ответ #27 : 29-11-2009 10:04 » |
|
Пример скачал из MSDN (правда он там на C#), ругаеться почти на все, начиная от обьявления SerialPort _serialPort; (типо необьявленная переменная).... Я так понял что я не включил библиотеку с етим класом, и как ето сделать не понимаю...
сделать это очень просто. Нужно добавить директиву using для конкретного пространства имён. using namespace System::IO::Ports;
|
|
|
Записан
|
|
|
|
mustelus
Участник
Offline
|
|
« Ответ #28 : 29-11-2009 19:31 » |
|
Так я так сделал, все равно не компили ТСя..... #using <System.DLL> #include "stdafx.h" #include "Form1.h" #include <windows.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <time.h> #include "devioctl.h" #include <setupapi.h> #include <basetyps.h> #include "BulkUsr.h" #include "usbdi.h"
using namespace Prilogenie; using namespace System; using namespace System::Security; using namespace System::Security::Permissions; using namespace System::Runtime::InteropServices; using namespace System::IO::Ports; [STAThreadAttribute]
делее все по-прежнему...
|
|
« Последнее редактирование: 30-11-2009 10:15 от Джон »
|
Записан
|
|
|
|
Вад
|
|
« Ответ #29 : 29-11-2009 20:20 » |
|
Ну, без текста ошибок компилятора и полного кода сказать ничего не могу - телепатических способностей не хватает
|
|
|
Записан
|
|
|
|
mustelus
Участник
Offline
|
|
« Ответ #30 : 30-11-2009 10:06 » |
|
Вот код: #using <System.DLL> #include "stdafx.h" #include "Form1.h" #include <windows.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <time.h> #include "devioctl.h" #include <setupapi.h> #include <basetyps.h> #include "BulkUsr.h" #include "usbdi.h"
using namespace System::Threading; using namespace Prilogenie; using namespace System; using namespace System::Security; using namespace System::Security::Permissions; using namespace System::Runtime::InteropServices; using namespace System::IO::Ports; [STAThreadAttribute]
int main(array<System::String ^> ^args) { //// Enabling Windows XP visual effects before any controls are created Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); //// Create the main window and run it Application::Run(gcnew Form1());
//// вот отсюда начинаеться моя вставка
bool _continue; SerialPort _serialPort;
string name; string message; StringComparer stringComparer = StringComparer.OrdinalIgnoreCase; Thread readThread = new Thread(Read);
// Create a new SerialPort object with default settings. _serialPort = new SerialPort();
// Set the read/write timeouts _serialPort.ReadTimeout = 500; _serialPort.WriteTimeout = 500;
_serialPort.Open(); _continue = true; readThread.Start();
Console.Write("Name: "); name = Console.ReadLine();
Console.WriteLine("Type QUIT to exit");
while (_continue) { message = Console.ReadLine();
if (stringComparer.Equals("quit", message)) { _continue = false; } else { _serialPort.WriteLine( String.Format("<{0}>: {1}", name, message) ); } } readThread.Join(); _serialPort.Close(); }; Вот ошибки: Warning 1 warning C4200: nonstandard extension used : zero-sized array in struct/union c:\project_for_vs\prilogenie_ii\prilogenie\usbioctl.h 437 Prilogenie Warning 2 warning C4200: nonstandard extension used : zero-sized array in struct/union c:\project_for_vs\prilogenie_ii\prilogenie\usbioctl.h 493 Prilogenie Error 3 error C2065: 'string' : undeclared identifier c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 37 Prilogenie Error 4 error C2146: syntax error : missing ';' before identifier 'name' c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 37 Prilogenie Error 5 error C2065: 'name' : undeclared identifier c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 37 Prilogenie Error 6 error C2065: 'string' : undeclared identifier c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 38 Prilogenie Error 7 error C2146: syntax error : missing ';' before identifier 'message' c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 38 Prilogenie Error 8 error C2065: 'message' : undeclared identifier c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 38 Prilogenie Error 9 error C3622: 'System::StringComparer': a class declared as 'abstract' cannot be instantiated c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 39 Prilogenie Warning 10 warning C4832: token '.' is illegal after UDT 'System::StringComparer' c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 39 Prilogenie Error 11 error C2275: 'System::StringComparer' : illegal use of this type as an expression c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 39 Prilogenie Error 12 error C2039: 'get' : is not a member of 'System::StringComparer::OrdinalIgnoreCase' c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 39 Prilogenie Error 13 error C3767: 'System::StringComparer::StringComparer': candidate function(s) not accessible c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 39 Prilogenie Error 14 error C2065: 'Read' : undeclared identifier c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 40 Prilogenie Error 15 error C2750: 'System::Threading::Thread' : cannot use 'new' on the reference type; use 'gcnew' instead c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 40 Prilogenie Error 16 error C2512: 'System::Threading::Thread::Thread' : no appropriate default constructor available c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 40 Prilogenie Error 17 error C2750: 'System::IO::Ports::SerialPort' : cannot use 'new' on the reference type; use 'gcnew' instead c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 43 Prilogenie Error 18 error C2582: 'operator =' function is unavailable in 'System::IO::Ports::SerialPort' c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 43 Prilogenie Error 19 error C2143: syntax error : missing ';' before '.' c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 54 Prilogenie Error 20 error C2143: syntax error : missing ';' before '.' c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 54 Prilogenie Error 21 error C2065: 'name' : undeclared identifier c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 55 Prilogenie Warning 22 warning C4832: token '.' is illegal after UDT 'System::Console' c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 55 Prilogenie Error 23 error C2275: 'System::Console' : illegal use of this type as an expression c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 55 Prilogenie Error 24 error C2143: syntax error : missing ';' before '.' c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 57 Prilogenie Error 25 error C2143: syntax error : missing ';' before '.' c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 57 Prilogenie Error 26 error C2065: 'message' : undeclared identifier c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 61 Prilogenie Warning 27 warning C4832: token '.' is illegal after UDT 'System::Console' c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 61 Prilogenie Error 28 error C2275: 'System::Console' : illegal use of this type as an expression c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 61 Prilogenie Error 29 error C2065: 'message' : undeclared identifier c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 63 Prilogenie Warning 30 warning C4832: token '.' is illegal after UDT 'System::String' c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 70 Prilogenie Error 31 error C2275: 'System::String' : illegal use of this type as an expression c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 70 Prilogenie Error 32 error C2065: 'name' : undeclared identifier c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 70 Prilogenie Error 33 error C2065: 'message' : undeclared identifier c:\project_for_VS\Prilogenie_ii\Prilogenie\Prilogenie.cpp 70 Prilogenie
|
|
« Последнее редактирование: 30-11-2009 10:15 от Джон »
|
Записан
|
|
|
|
Вад
|
|
« Ответ #31 : 30-11-2009 10:47 » |
|
Ну вот. Теперь видно. 1. Error 3 error C2065: 'string' : undeclared identifier неизвестный тип string ("'string' : undeclared identifier") - Действительно, ты какой тип под ним имел в виду? В C# есть такой встроенный тип, а в C++ есть только std::string и дотнетовский System::String. Первый не подходит, потому что пространство имён std не указано, а второй из-за чувствительности языка к регистру. 2. Error 9 error C3622: 'System::StringComparer': a class declared as 'abstract' cannot be instantiated - и несколько последующих, связанных с ней. Ты пытаешься создать абстрактный класс с помощью конструктора копирования, что нельзя. На самом деле, здесь скорее всего требовалось использовать тип-ссылку (StringComparer^ ), хотя в дотнетовских тонкостях применительно к C++ я не очень секу. 3. Error 14 error C2065: 'Read' : undeclared identifier Солидарен с компилятором. Совершенно непонятно, что это за Read и откуда он взялся. 4. Error 15 error C2750: 'System::Threading::Thread' : cannot use 'new' on the reference type; use 'gcnew' instead Надо слушать компилятора и не пытаться втиснуть C#-ный код в C++: беглый просмотр документации в MSDN для класса Thread даёт следующий пример правильного создания потока: Thread^ oThread = gcnew Thread( gcnew ThreadStart( &ThreadExample::ThreadProc ) );
5. Error 17 error C2750: 'System::IO::Ports::SerialPort' : cannot use 'new' on the reference type; use 'gcnew' instead Та же фигня, что и п.4 6. Ну и напоследок, с консолью тоже напортачено (точнее, с вызовом статических методов): Error 23 error C2275: 'System::Console' : illegal use of this type as an expression А теперь глядим документацию в MSDN, пример для сиплюсплюса (там даже по русски): Console::Write( L"Hola " ); Console::WriteLine( L"Mundo!" ); Console::WriteLine( L"What is your name: " );
Резюме: не надо, НЕ НАДО копировать код и надеяться, что как-нибудь так заработает. Особенно если языки разные Ну и RTFM, конечно.
|
|
« Последнее редактирование: 30-11-2009 10:52 от Вад »
|
Записан
|
|
|
|
|
mustelus
Участник
Offline
|
|
« Ответ #33 : 06-12-2009 10:25 » |
|
Господа, может, какую книгу посоветуете по C++/CLI, а то я вскользь просматривал по книге Айвора Хартона VS C++ 2005 Базовый курс, но по-моему, этого маловато... (по возможности бесплатной ссылкой поделитесь).
|
|
« Последнее редактирование: 07-12-2009 07:56 от Sel »
|
Записан
|
|
|
|
|