How can i call function in WindowsApplication.cpp?

Hi!

I will try to call function in WindowsApplication.h, WindowsApplication.cpp.

How can i call function in WindowsApplication.cpp?

Which function?

Do you want to run a function from FWindowsApplication? Or just make a new function inside it and run it somehow?

I think that to get access to the FWindowsApplication you can use

(FWindowsApplication*)(FPlatformMisc::CreateApplication())

which should return the pointer to the GenericApplication which you should be able to cast to the FWindowsApplication and use it’s functions.

But the function’s name is worrying because it says it creates application, not getting the current, running instance. I think that to get it you will have to make new method.

Why do you need it anyway?

Thanks for your answer. zompi2.

At first, i wanted to call only function in FWindowsApplication.
But now, i want to create function in FWindowsApplication and use it.

Because I will include thirdparty static library in my program.
It not worked correctly by compile error.

Then i try to include by orginal c++ program method(ex. #pragma comment(lib, “testlib.lib”) in FWindowsApplication.

If you want to add ThirdParty library (called testlib) you should add libraries with headers to the Engine/Source/ThirdParty/testlib

Check how other libraries are added, for example libcurl or WebSockets to get a better picture. Then you just have to add PublicDependencyModuleNames of “testlib” to the Core.Build.cs somewhere, so the engine will use this library.

After that you should be able to include the header of the library and use it inside the Core module.

#pragma comment(lib, "testlib.lib")
should work but it is quite inelegant :wink:

If you are digging so deep in the engine it won’t be a bad idea to add a getter to the WindowsApplication. My suggestion is to create a static getter in FWindowsApplication that returns FWindowsApplication* WindowApplication and a public interface in FWindowsPlatformMisc (because it has access to the FWindowsApplication) that will get it.

You don’t need to link the lib into the application. The whole point of modules is that you can create a module that contains your unique library without having to modify our base code. See the Apsalar plugin source as an example

Hi! zompi2.

First, thanks you for detailed answer.

I created Build.cs file for testlib and added PublicDependencyModuleNames of “testlib” to the Core.Build.cs.
Then it worked correctly in WindowsApplication.

But i can’t understand to create a static getter and public interface.
I can’t use testlib function in my own project.

Can you descripe more detail?

Sorry to bother you.

First of all: Do you really need to use your library inside the FWindowsApplication not anywhere?

When you add the PublicDependencyModuleNames of “testlib” in Build.cs of yout project you should be able to use Your library inside the game, not engine.

And you should do this, not dig around the core part of the engine. Unless the library needs some part of WindowsApplication which are private.

If you really need to get the WindowsApplication then:

In WindowsApplication.cpp in line 39 you have a pointer to the current WindowsApplication:

FWindowsApplication* WindowApplication = NULL;

You need to get it. Write a static public getter function, like:

FWindowsApplication* FWindowsApplication::GetWindowsApplication()
{
return WindowApplication;
}

The part about the interface… it’s not a good idea, my bad. The solution above should work.

Because

  • i have to initialize variables when windows is created, and call that.

  • i have to add windows message(WM_USER + @).

I added statements :

  • WindowsApplication.h

    static FWindowsApplication* GetWindowsApplication();

  • WindowsApplication.cpp

static FWindowsApplication* GetWindowsApplication()
{
return WindowApplication;
}

But, i can’t call GetWindowsApplication function in my project.

To get access to the FWindowsApplication instance from the game you need to write a getter (because the Engine isn’t give an access to it by default).

In WindowsApplication.h in public section of class FWindowsApplication add:

static FWindowsApplication* GetWindowsApplication();

In WindowsApplication.cpp add:

FWindowsApplication* FWindowsApplication::GetWindowsApplication()
{
	return WindowApplication;
}

In WindowsPlatformMisc.h in FWindowsPlatformMisc struct add:

static class GenericApplication* GetApplication();

In WindowsPlatformMisc.cpp add:

GenericApplication* FWindowsPlatformMisc::GetApplication()
{
	return FWindowsApplication::GetWindowsApplication();
}

Now in the game in the file when you want to use WindowsApllication #include “WindowsApplication.h” and use it like:

((FWindowsApplication*)FPlatformMisc::GetApplication())->PumpMessages(10.f);

I hope it will help.

Sorry for such a hiatus. I tried to get an access to the WindowsApplication from the game and I think I’ve done it. I posted a solution in answer. Please confirm if it works.

(And and yet it need interface…)

Hi!
Thanks for answer.

Where can i find Apsalar plugin source?

Hi! zompi2.

Thanks for answer.

It’s very helpful to me.

It’s part of the source up on GitHub. It’s in the Plugins/Runtime subdiretories