# How can i call function in WindowsApplication.cpp?

**URL:** <https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658>\
**Category:** Platform & Builds\
**Tags:** window, unreal-engine, UE4, CPP, question\
**Created:** [January 22, 2015, 6:35am UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658 "2015-01-22T06:35:37Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![user\_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@user\_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd](https://forums.unrealengine.com/u/user_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd)\
**Post date:** [January 22, 2015, 6:35am UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/1 "2015-01-22T06:35:37Z")

</div>

Hi!

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

How can i call function in WindowsApplication.cpp?

---

<div class="post-metadata">

**Author:** ![joeGraf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@joeGraf](https://forums.unrealengine.com/u/joeGraf)\
**Post date:** [January 22, 2015, 4:35pm UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/2 "2015-01-22T16:35:43Z")

</div>

Which function?

---

<div class="post-metadata">

**Author:** ![zompi2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zompi2/32/937524_2.png) [@zompi2](https://forums.unrealengine.com/u/zompi2)\
**Post date:** [January 22, 2015, 10:45pm UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/3 "2015-01-22T22:45:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![user\_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@user\_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd](https://forums.unrealengine.com/u/user_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd)\
**Post date:** [January 23, 2015, 3:21am UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/4 "2015-01-23T03:21:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zompi2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zompi2/32/937524_2.png) [@zompi2](https://forums.unrealengine.com/u/zompi2)\
**Post date:** [January 23, 2015, 10:24am UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/5 "2015-01-23T10:24:00Z")

</div>

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 😉

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.

---

<div class="post-metadata">

**Author:** ![joeGraf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@joeGraf](https://forums.unrealengine.com/u/joeGraf)\
**Post date:** [January 23, 2015, 5:08pm UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/6 "2015-01-23T17:08:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![user\_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@user\_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd](https://forums.unrealengine.com/u/user_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd)\
**Post date:** [January 25, 2015, 8:09am UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/7 "2015-01-25T08:09:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zompi2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zompi2/32/937524_2.png) [@zompi2](https://forums.unrealengine.com/u/zompi2)\
**Post date:** [January 25, 2015, 9:18pm UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/8 "2015-01-25T21:18:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![user\_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@user\_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd](https://forums.unrealengine.com/u/user_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd)\
**Post date:** [January 26, 2015, 4:01am UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/9 "2015-01-26T04:01:30Z")

</div>

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

- WindowsApplication.cpp

static FWindowsApplication\* GetWindowsApplication()  
{  
return WindowApplication;  
}

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

---

<div class="post-metadata">

**Author:** ![zompi2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zompi2/32/937524_2.png) [@zompi2](https://forums.unrealengine.com/u/zompi2)\
**Post date:** [January 27, 2015, 12:21pm UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/10 "2015-01-27T12:21:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zompi2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zompi2/32/937524_2.png) [@zompi2](https://forums.unrealengine.com/u/zompi2)\
**Post date:** [January 27, 2015, 12:22pm UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/11 "2015-01-27T12:22:34Z")

</div>

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…)

---

<div class="post-metadata">

**Author:** ![user\_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@user\_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd](https://forums.unrealengine.com/u/user_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd)\
**Post date:** [January 28, 2015, 2:17am UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/12 "2015-01-28T02:17:54Z")

</div>

Hi!  
Thanks for answer.

Where can i find Apsalar plugin source?

---

<div class="post-metadata">

**Author:** ![user\_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@user\_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd](https://forums.unrealengine.com/u/user_5a6bfd32b1a7349a5f1413349459e191f21a52a9f5b6c819e33abd)\
**Post date:** [January 28, 2015, 5:47am UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/13 "2015-01-28T05:47:39Z")

</div>

Hi! zompi2.

Thanks for answer.

It’s very helpful to me.

---

<div class="post-metadata">

**Author:** ![joeGraf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@joeGraf](https://forums.unrealengine.com/u/joeGraf)\
**Post date:** [January 28, 2015, 6:27am UTC](https://forums.unrealengine.com/t/how-can-i-call-function-in-windowsapplication-cpp/304658/14 "2015-01-28T06:27:14Z")

</div>

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