C++ GamerServer Library with Unity Client - c++

I made a simple C++ game server library(network session) and I wanted to use it for Unity client to make a simple MMORPG.
I found that my library needs to be changed to DLL.
So, I made a dll of my C++ game server library and found that my class cannot be used for Unity Client directly.
Is there an easy way to use my c++ library class for Unity Client?
I hope your wise answers.
Thank you for reading.

You are trying to create a Unity native plugin. You have to make sure that you export your methods in the proper way and then you can "link" them to a C# method that will have the same signature. Tip: make sure to keep with the native/primitive types. Since it is a long topic to be explained here I am sharing a link that will help you:
Working with Native Plugins from Unity: https://learn.unity.com/tutorial/working-with-native-plugins-2019-3

Related

program NSTouchBar with c++

The problem
I would like to use c++ to create an application that uses the new macbook pro touch bar. However I am not able to find any really good resources. And apple does not have any docs on using c++ to program the touch bar.
What I have done
I found this article on c++ and the touch bar, However I cannot find either of the header files for the script GLFW/glfw3.h and GLFW/glfw3native.h. These both seem critical to the script working.
More on the issue
Even if the above article's script works, there are no official docs for programing the touch bar with c++ (That I know of). I think that this is an important thing to have given the fact that many, if not most applications are written in c/c++.
Thank you in advance for the help!
So the article that you link to basically does not need the GLFW/glfw3.h and GLFW/glfw3native.h files if you are not using GLFW.
What UI framework are you using for your C++ app?
Unless it is still using Carbon, at the lowest level, the framework will be creating NSWindows to actually have windows in the UI. You need to get access to the NSWindow that your framework is using to host it the UI. If it is still using Carbon, I think you are probably not going to be able to accomplish this.
If the framework provides some mechanism to get the native platform window (which will be an NSWindow), you would replace the author's call to glfwGetCocoaWindow(window); with the correct call from your framework.
If the framework does not provide access to the NSWindow, then you will need to use the code that is commented out at the bottom of the article to attach your touchbar to the windows in your app.
Please note that all that code is Obj-C code; you'll need to have at least one .m or .mm file in your project to provide that Obj-C glue code to get access to the touchbar. Basically that code is a C-calleable wrapper around the Cocoa API.
Also note that you'll need to expand the list of buttons and actions for all the different things you want to put in the touchbar. You could add your own wrapping API so that the construction of the toolbar is done from C++ and registers actions that call-back into your C++ app to handle the events.
Fundamentally though, the touchbar is not available on any other platform, so there is no great benefit to trying to avoid writing Obj-C to implement your touchbar as that code will only run on macOS anyway. If you use .mm files to implement Obj-C++ for this code, you can still call into your C++ objects from your touchbar code.

Microsoft ANGLE for uwp

guys! I'm currently working on new cross-platform application (iOS, Android, UWP). I have graphical library for UI written in c++, using freeglut for opengGL.
The problem is, I don't know how to use this library in my UWP application. I have read a lot of information about all the wrappers for OpenGL, but they all for WPF or written in C++. I also know about Microsoft ANGLE Project, but it is written in the c++ too, but I need to write the application in C# language.
So, how can I modify my own library using excluding freeglut and import it into my C# application?
By the way, sorry for mistakes in my English.
So you want to consume your legacy C++ assembly in your UWP application?
You can create a Windows Runtime Component(Universal Windows) project, in which you need to include the assembly, and declare as many APIs as you want to expose, all marked with DllImport attribute.
Eventually, this WinRT component will do the Platform Invoke, and works as a "wrapper" layer between your legacy code and UWP application.
It's up to your preference which language you use for the WinRT component, C++ or C#, either way, you need to worry about struct/type mashalling and unmashalling.
After you're done with above, you'll be able to reference the WinRT component in your UWP application, and call the APIs you declared in that assembly.
The same way works for Microsoft Angle project as well.
You might find this post useful.
One last word, you might want to avoid using forbidden APIs, otherwise your UWP app won't pass the Windows Store Certification.
According to https://msdn.microsoft.com/library/windows/desktop/jj714080.aspx there is an option to use DirectX and some native API functions including LoadLibrary and GetProcAddress functions https://msdn.microsoft.com/library/windows/desktop/jj714080.aspx
This should give you ability to use any native dll.
You can try to make RuntimeComponent project and put it there. Also you can try clr oldsyntax option to use native code as it is.

Accessing Windows 10 functions from Unity IL2CPP project via a class library

I have been trying to create a UWP class library that gives me access to Windows 10s native features such as Windows.Security.Authentication.OnlineId. I would like to get a username and ID from the device for use in a Unity UWP IL2CPP project. I am currently able to do this with Unity's built in social class for ios and there is code which google has written that allows this to work seamlessly with the same class but for android's Google Play Games.
I've downloaded a sample off github (https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/WebAccountManagement) which demonstrates how to call the relevant classes and functions in a UWP app and works well but the samples appear to be are accessing classes from the "Windows.Foundation.UniversalApiContract" class.
I can't seem to find a way to add this to a basic UWP class library so I can call on the required classes such as Windows::Security::Credentials::WebAccountProvider.
The best I've been able to do is create a basic function in the class library that returns a small hardcoded string just to test if the concept was remotely possible.
:-
extern "C" __declspec(dllexport) wchar_t* __stdcall GetMyString()
{
wchar_t* myString = L"Guuuper";
auto resultBufferLength = wcslen(myString) + 1;
wchar_t* result = static_cast<wchar_t*>(CoTaskMemAlloc(resultBufferLength * sizeof(wchar_t)));
wcscpy_s(result, resultBufferLength, myString);
return result;
}
My whole journey in attempting to do that can be found here:-
http://forum.unity3d.com/threads/returning-c-string-to-il2cpp-windows-store-project.395284/
I've been able to successfully call this code from within unity via a UWP build but my main question is how I would go about adding the appropriate references or how I would create this class library to access the WebAccountProvider class?
Any help would be much appreciated
Update: I have asked the MS team at their own site about this challenge and they appear to be working on a solution.
Apologies for 'answering' and not 'commenting' but I'm still a new contributor.
My initial first instinct is to suspect that your problem isn't with Unity3D; it's with C# and the entire programming environment inside Unity3D. C# does not allow for unmanaged memory allocation. There's an entire art of getting C++ libraries to work in C#, and it's called "Marshaling" code, and there's an entire industry based around marshaling plugins from C++ to Unity3D as a result.
The reason you're not getting a string, is because you're literally sending and receiving a pointer to a single character.
Unfortunately, my single experience marshaling C++ code for Unity was five years ago and I'm a little rusty on what my solutions were. What I do remember is that the most 'hacky' but obvious solution was to work out the maximum size of string that could possibly be passed, and, on both sides of the divide, pass and receive strings of that predefined size.
https://learn.microsoft.com/en-us/dotnet/framework/interop/default-marshaling-for-strings
Let us know if that sends you in the right direction.

How do I use the windows network API in Qt?

I am going to put an network status icon in my GUI application. To get the network status notification, I am trying to use the Windows API. For this I am thinking to use NetworkAvailabilityChangedEventHandler in my application. I am very new to programming with the Windows API and framework. Can anybody help me in the following things:
Can the API NetworkAvailabilityChangedEventHandle only be used in C#?
Can I use it in C++ (Qt)?
Which header file must I include? (I checked in MSDN for this. but they are using namespace for this. All the examples are in C#. I am not able to understand how to implement it in my C++ code.)
I will be grateful if somebody can give me a detailed code snippet for using this windows event handler, including the .h file or namespace to be included.
Where did you get the idea to use the NetworkAvailabilityChangedEventHandler delegate?
That is explicitly not part of the Windows API, but rather a delegate function used by the .NET Framework in conjunction with the NetworkChange.NetworkAvailabilityChanged event. That explains why all the examples on MSDN are in C#—because this is only intended to be used in applications targeting the .NET Framework. If you're writing unmanaged C++ using Qt, then you're not using the .NET Framework, and you can't take advantage of its functionality.
The Windows API equivalent is the InternetGetConnectedState function, which returns a value indicating whether or not the system is currently connected to the Internet. You'll find that its MSDN documentation is substantially friendlier towards unmanaged C++ developers, because that's the
primary intended audience. The information that you're seeking is given at the bottom:
Header Wininet.h
Library Wininet.lib
DLL
Wininet.dll
You can find a list of all the WinINet functions here.

I am using a comet server and I want it to interact with C++

I am using persevere for an application I am writing that controls remote hardwere.
Persevere is written in Java and doesn't supply an alternative API.
I am using a web-based GUI as the control panel. So far, so good.
I can get and set data using REST channels like dojo does but the problem is that I don't really know how to use REST channels. Which library should I use to do so?
If you use gcc as your toolchain you can embed a JVM with GCJ to run persevere inside your application. GCJ makes it easy to call C++ from Java with it's CNI interface (much easier than JNI). I used that method to use Java scripting inside our C++ application. You can even compile the persevere jar into a native library and link it to your app with GCJ.
The best reference is the GCJ Documentation.
There is also a Linux Journal contains the article Embedded Java with GCJ that you can read.
You can also study applications that use gcj.