How to load OF app built as DLL from other app

Hi, I’m trying to build my OF app as .dll file and then dynamically load it from other app.

First of all, I could successfully generate .dll and .lib file by simply changing the Configuration type in the Property and then building the project.

I would like to simply test opening this DLL file from other app and see if the OF window can be created.

Would it be even possible to do this? If so, what would the basic process be like? I would appreciate any advice. Thanks!

1 Like

I could successfully open the compiled DLL file and see the window being created.

All I did was adding the below code in main.cpp below int main() {}

#define EXTERN __declspec(dllexport)
extern "C"
{
	EXTERN void createWindow()
	{
		std::cout << "CREATING THE WINDOW" << std::endl;

		ofSetupOpenGL(1024, 768, OF_WINDOW);			// <-------- setup the GL context

														// this kicks off the running of my app
														// can be OF_WINDOW or OF_FULLSCREEN
														// pass in width and height too:
		ofRunApp(new ofApp());
	}
}

And then copy the generated .dll and .lib file to my loader app’s project folder(I had to also copy other .dll dependencies too)
And then link the generated .lib file by adding the file name in Property -> Linker -> Input -> Additional Dependencies.

And import the function by adding the below code to header file of my loader app.

#define DECLDIR __declspec(dllimport)


extern "C"
{
	DECLDIR void createWindow();
}

And in cpp file, I simply called the function like this.

int main()
{
	createWindow();
	return(1);
}

And then if I run the app, I could see the OF window being created.

1 Like

Although it works well when I build in 64bit, when I build the DLL file in 32bit(x86) using the same code and method, I could not load the file from the loader app.
When I run the loader app, it crashes with the following error.

If I comment out ofSetupOpenGL() and ofRunApp() and build DLL again, it works without the crash. I think the problem occurs while creating the OF window. (calling ofCreateWindow() caused the crash too)

If I make the OF app executable it works fine even on 32bit build.

What would be the possible cause of the crash when loading the DLL file built in 32bit?
I would appreciate any help!

I just figured out that I should also copy all other dependencies once I build the DLL in 32bit. Copying the 32bit DLL with all other dependencies(i.e fmodex.dll) to the loader app’s project folder fixed the problem.
Thanks!

1 Like