x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to use System namespace and library through MS Visual Studio in UE4 C++ project?

Dear community and staff,

A personal project of mine, namely controlling a wireless toy cannon from a user interface built with the Unreal Engine has been blocked for while now. I can't seem to integrate the Microsoft Windows platform serial communication directly into a C++ class in the Unreal Engine 4.

Edit 2015-02-21: To summarize, I am trying to use a System::IO::Ports::SerialPort in my project.

Below is a minimal code snippet to reproduce the problem, with marked known compilation failures. Thank you for any feedback, suggestion, comments.

In SerialPort.h file:

 #pragma once
 
 #include "GameFramework/Actor.h"
 #include "SerialPort.generated.h"

 #using <System.dll> // 1. Compilation failed: Unrecognized compiler directive using
 using namespace System; // 2a. Compilation failed: error C2871: 'System' : a namespace with this name does not exist
     
 UCLASS()
 class TEST_API ASerialPort : public AActor
 {
     GENERATED_BODY()
     
 public:    
     // Sets default values for this actor's properties
     ASerialPort();
 
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
     
     // Called every frame
     virtual void Tick( float DeltaSeconds ) override;

     // Serial port methods aggregation removed from the example for simplicity: connect(), write(), etc...

 private:
     System::IO::Ports::SerialPort _port; // 2b. Also: Compilation failed: error C2871: 'System' : a namespace with this name does not exist
 };

Additional notes:

This is a very specific project, for MS Windows deployment only, more of a toy really. I have both pieces working separately: front end and back end serial port in other projects of mine. I have added CLR support in the project, general configuration properties. I believe I added dependencies and includes to the project.

Please let me know of any suggestion or question. Thank you, Fen

Product Version: Not Selected
Tags:
more ▼

asked Feb 20 '15 at 06:51 AM in C++ Programming

avatar image

F3NR1S
127 5 15 18

avatar image Allar Feb 20 '15 at 07:28 AM

What exactly are you trying to do with

 #using <System.dll>

This isn't valid C++ syntax at all.

avatar image F3NR1S Feb 20 '15 at 05:24 PM

Well yes but, it is compiler specific and works with MSVC++. The standalone version works just fine. It is likely a tool chain specific constraint in my case.

avatar image ngrts Feb 20 '15 at 11:56 AM

Unreal's Build Tools and friends do all the actual work. VS is basically only just for editing source files in nice GUI. You need to add in some flag via the Project.Build.cs or Project*.Target.cs files. Quick search shows you'll need to set CLRMode = CPPCLRMode.CLREnabled somewhere.

./Source/Programs/UnrealBuildTool/Configuration/UEBuildModule.cs

avatar image F3NR1S Feb 20 '15 at 05:25 PM

Hm... I see, another route might be to build a standalone DLL and link it to the project for that class, following the tutorial for linking libraries.

avatar image ngrts Feb 20 '15 at 06:19 PM

If you search the forums for Kinect v2, you can see how they did it. Or ask on their thread. Must have run into what you did.

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

I was eventually able to control my toy cannon from the unreal engine menu I created, controlled through a .Net framework DLL using the System SerialPort. I will post a brief video about the project next week, the article which was the starting point for solving the situation was: https://wiki.unrealengine.com/Linking_Dlls I will add further to this article and enhance it for everyone to reuse the work. All in all this question is solved. Thank you everyone.

more ▼

answered Mar 02 '15 at 05:40 AM

avatar image

F3NR1S
127 5 15 18

avatar image F3NR1S Mar 21 '15 at 08:33 PM

As promised, the wiki article for linking DLL has been updated with all of what I learned. And I recorded a video of the little project I used this knowledge for. It was pretty awesome to work on this with the Unreal Engine. Enjoy.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question