LPT ansteuern aber mit C++ und .Net
-
#include "inpout32.h"
So hab ich es in die Projektname.cpp eingefügt nach
#include "stdafx.h"
und nach allen anderen Form Headern.
Aber wie soll ich die LIB linken?? Ich hab sie einfach im Projektverzeihniss. Ich kenn mich da nicht so gut aus.
-
#pragma comment(lib, "name-der.lib")
-
So? Aber dann kommt immer noch der Fehler.
// Robot Controller.cpp : main project file. #include "stdafx.h" #include "Konfig.h" #include "Form1.h" #include "inpout32.h" #pragma comment(lib, "inpout32.dll") using namespace RobotController; [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()); return 0; }
-
Welcher Fehler denn?
Und was steht in "inpout32.h" drin?
-
inpout.h :
#pragma once using namespace System; using namespace System::Runtime::InteropServices; // Für DllImport ref class inpout32 { public: inpout32(void); [DllImport("inpout32.dll", EntryPoint="Out32")] static void Output(int adress, int value); };
Fehler:
: error C2653: 'inpout32' : is not a class or namespace name
: error C3861: 'Output': identifier not found
-
Also: Nochmals zum langsamen mitdenken...
1. Du kannst ganz normal LIB-Dateien linken und ganz normal (alte/native) C/C++ Funktionen aufrufen. Das ist der einfachst/schnellste und auch bevorzugste Weg InterOp in C++/CLI zu machen!!!
2. Du kannst von Hand eine Funktion einer mittels DllImport-Attribute einfügen.
Du bringst gerade beide durcheinander...
Entscheide Dich mal was Du willst, dann kann ich Dir weiterhelfen...
-
Ok, dann nehme ich die zweite aber was muss ich dan am Code ändern, ist das erste mal das ich mit libs arbeite.
-
Du arbetest nicht mit LIBs...
Und includiere "inpout32.h" in die cpp-Datei wo Du die Methoden auch verwenden willst.
-
Danke, es geht nun alles, nur noch eins:
Wie mach ich das mit Input?
Wenn ich die Funktion einfach so hinzufüge kommt nen Error:
static void Input(int adress);
1>Robot Controller.obj : error LNK2020: unresolved token (06000012) inpout32::Input
1>inpout32.obj : error LNK2020: unresolved token (06000003) inpout32::Input
1>C:\Dokumente und Einstellungen\BNightSpeeder\Eigene Dateien\Visual Studio 2005\Projects\Robot Controller\Debug\Robot Controller.exe : fatal error LNK1120: 2 unresolved externals
-
Hab es nun so:
ref class inpout32 { public: //LIB Funktionen inpout32(void); //Input/Output Befehle //Output [DllImport("inpout32.dll", EntryPoint="Out32")] static void Output(int adress, int value); //Input [DllImport("inpout32.dll", EntryPoint="Inp32")] static void Input(int adress); };
Edit: Hat sich erledigt.