Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Coffee corner » [SOLVED]Sharing Ptr of object to dll
[SOLVED]Sharing Ptr of object to dll [message #52172] Thu, 01 August 2019 15:09 Go to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello community,

I have a programm wich load a dll. This dll carry class wich have a public attribut "object* object;"
this public attribut is fill by my main programm like that: ptrToTheClass->object = myMainObjectPtr;

then when I use method of my dll wich use the objectDll ptr it crash.
However my objectDll Ptr have the right address of the main object so I dont get why it crash.
(I have checked by using log and the problem occur when I call method of ptrToTheClass->object)

Someone have an idea ? maybe I can't share object between my Dll instance of object and my programm ?

here I show you :
Method of my dll:
void Discord_Minecraft::launchCommande(ValueMap payload){
	ptrBot->CreateMessage(ChannelLastMessage, "SmartUppBot DLL hot LOAD !"); //the crash occur here (the ptrBot addr is right)
}


here is creation of Discord_Minecraft object and filling of ptrBot :
			
DiscordModule* test = facto(); //Test is my Discord_Minecraft DLL object
test->ptrBot = getBotPtr(); // here I fill ptrBot 


Thanks in advance.
Best Regard.

[Updated on: Wed, 07 August 2019 09:53]

Report message to a moderator

Re: Sharing Ptr of object to dll [message #52175 is a reply to message #52172] Fri, 02 August 2019 09:02 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Xemuth wrote on Thu, 01 August 2019 15:09

Someone have an idea ? maybe I can't share object between my Dll instance of object and my programm ?


Literally a lot of things can go wrong here. For starters, try to "USEMALLOC". Anyway, in general, sharing should work.

Mirek
Re: Sharing Ptr of object to dll [message #52178 is a reply to message #52175] Fri, 02 August 2019 13:19 Go to previous messageGo to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
mirek wrote on Fri, 02 August 2019 09:02
Xemuth wrote on Thu, 01 August 2019 15:09

Someone have an idea ? maybe I can't share object between my Dll instance of object and my programm ?


Literally a lot of things can go wrong here. For starters, try to "USEMALLOC". Anyway, in general, sharing should work.

Mirek


Hello Mirek, I have try and it change nothing but I have digging deeply my code and the crash occure when, in the dll I want do this kind of thing :
       
        req.New(); //req is HttpRequest Object, When I'm in debug mode, the crash occure here
        Json json("content", message);
		req.Url(baseUrl); // When I'm in release the crash occure here
		req.Path("/api/channels/" + channel + "/messages");
		req.POST();
		req.Post(json);
		String response =req.Execute();
        LOG(response);
        ValueMap m = ParseJSON(response);
        ApplyRateLimits(req);
        LOG(req.GetContent());


Seems like I have trouble to use HttpRequest within DLl even if Core and Core/SSL are built in.

May Request/Socket work differently when built in Dll ? Shocked
Re: Sharing Ptr of object to dll [message #52183 is a reply to message #52172] Sun, 04 August 2019 14:35 Go to previous messageGo to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello again,

By trying to create new HttpRequest (and activate trace()) from dll function and use it.
extern "C" __declspec(dllexport) String __cdecl test(){
	HttpRequest reqApi("https://chucknorrisfacts.fr/api/get?data=nb:1;type:txt;tri:alea");
	reqApi.TRACE();
	reqApi.GET();
	ValueMap json = ParseJSON(reqApi.Execute());
	if(~json[0]["fact"].GetCount())
		return ~json[0]["fact"];
	else 
		return " Error ";
}

This message appear :
https://i.imgur.com/659yOA0.png
It's clear but not clear (from my point of view) Very Happy

is there a flag to fix it or another way of using HttpReq ?
What is GetIniKey ?

Thanks in advance
Best regard

[Updated on: Sun, 04 August 2019 20:30]

Report message to a moderator

Re: Sharing Ptr of object to dll [message #52186 is a reply to message #52172] Tue, 06 August 2019 16:21 Go to previous messageGo to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Nobody have an idea ?:'(
Re: Sharing Ptr of object to dll [message #52187 is a reply to message #52186] Tue, 06 August 2019 22:24 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Xemuth wrote on Tue, 06 August 2019 10:21
Nobody have an idea ?:'(

I just searched Upp source code (Ctrl-Shift-F) for GetIniKey. Smile

String GetIniKey(const char *id, const String& def) {
	ASSERT_(IsMainRunning(), "GetIniKey is allowed only after APP_MAIN has started");
	Mutex::Lock __(sMtx);
	return sIniKeys().Get(id, def);
}
bool  IsMainRunning()
{
	return sMainRunning;
}

sMainRunning is set in CommonInit(). Try to use search Smile
CommonInit() is called by various initialization functions.
In the end it is called by GUI_APP_MAIN/CONSOLE_APP_MAIN.
Because you are not calling GUI_APP_MAIN/CONSOLE_APP_MAIN in your DLL, you are getting this assert.
Try to call CommonInit() manually during initialization of your DLL.

Hope this helps.


Regards,
Novo
Re: Sharing Ptr of object to dll [message #52188 is a reply to message #52187] Tue, 06 August 2019 22:29 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Do not forget that your DLL is containing another copy of U++. That includes memory allocator. And this means that if you somehow allocated memory in your DLL, then you should free it inside of this DLL. The same is related to your app.

Have fun!


Regards,
Novo
Re: Sharing Ptr of object to dll [message #52189 is a reply to message #52172] Wed, 07 August 2019 09:25 Go to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello Novo,

Thanks for your response. I did a research via Ctrl-Shit-F ANd I find the GetInitKey() but
indeed and here it is my bad, I did not look where "sMainRunning" were set to true.

After looking at "CommonInit()", this one is not defined outside of App.cpp so can't be called.
But, to do initialization of Upp from function/main we have to do it like this :
#include <Core/Core.h>
using namespace Upp;

int main(int argc, char *argv[]){
	AppInit__(argc, (const char **)argv);
...

Then to free it we must do this :
AppExit__();
return UPP::GetExitCode();
}


Again, Thanks for your help.
Previous Topic: Map implementation
Next Topic: What is the minimum OpenGL version required for GLCtrl?
Goto Forum:
  


Current Time: Thu Mar 28 22:30:20 CET 2024

Total time taken to generate the page: 0.01221 seconds