ADLINK-IST / opensplice

This is the Vortex OpenSplice Community Edition source repository. For our commercial offering see
https://www.adlinktech.com/en/vortex-opensplice-data-distribution-service
Apache License 2.0
259 stars 155 forks source link

Can not execute simplest dll-based invocation #108

Closed fresh-ji closed 4 years ago

fresh-ji commented 4 years ago

Hi, recently i have been learning the isocpp2-API-based examples in PXXX-VortexOpenSplice-6.9.181018OSS-HDE-x86_64.win-vs2017-installer. I built my own dll-based application, but the dds-related sentences can not be executed. Full codes provided below:

捕获1 dll header

捕获2 dll source

捕获3 main

everytime the program enters dll corretly, when executing "dds::domain::DomainParticipant dp(org::opensplice::domain::default_id());", the cmd window pauses for a few seconds and shuts itself down, nothing else happen.

sorry to disturb you, but i am very confused about this.

thanks.

ThijsSassen commented 4 years ago

@fresh-ji looking at your code this would be expected behavior. You only create a domain allocated to a local variable dp and then your function returns resulting in the domain running out of scope and terminating itself. Please look at the Isocpp2 documentation for more information on how it works.

fresh-ji commented 4 years ago

i am sorry that i did not express myself clearly, but the application really terminates unnormally. 捕获2

捕获1

i executed it in PowerShell. You can see that "that point" did not printed.

Today i reconsidered it again, i noticed that "#include " may be the reason, my ide is vs2013. is this a proper way to invoke dds-api in dll?

thanks!

ThijsSassen commented 4 years ago

@fresh-ji I think what you seeing is the termination behavior of OpenSplice. When the domain participant runs out of scope it will be cleaned up and when the last domain participant is gone the application will be terminated with an exit call resulting in termination of your application. To prevent this you could keep a global reference to the dp variable resulting in OpenSplice not terminating.

fresh-ji commented 4 years ago

But in fact i did not do anything else in my application, whatever i write behind "dds::domain::DomainParticipant dp(org::opensplice::domain::default_id());" can not be reached. So i think the domain participant could not run out of scope.

i looked over #99 https://github.com/ADLINK-IST/opensplice/issues/99 and i think the problems may be the same.

when i doing this process not in dll-way, everything goes right; and i add "#include " to it, the same situation happens; so i think the problem is Windows SDK or something.

Now if i want to package the dds-api into dll and invoke it in pure-C environment, what is the right way to do without using "#include "?

ThijsSassen commented 4 years ago

@fresh-ji To compile an isocpp2 application on windows please see this One of the steps is that any include file from OpenSplice should be done before including Windows.h to avoid memory heap crashes.

fresh-ji commented 4 years ago

very appreciate for your answer. putting Windows.h backwards could make the non-dll application run correctly. but i use "LoadLibrary" to load dll, which do not use any include file from OpenSplice, only Windows.h, so the problem is still exists. i am going to reconsider the framework to avoid it. Thanks!

Here is my anothor confusion. when i run my another application, the publisher writes messages every one second, the subscriber takes them and shows in console, for total 19 messages. But everytime the subscriber receives the first message two times("initederate"), you can see from the figure, at 0.00 and 0.06. i am for sure my "initederate" sends only once, how the second message been received? at last of figure, the "letusendit" also receives twice, which was sent only once. thanks for looking through this. 捕获

ThijsSassen commented 4 years ago

@fresh-ji what code are you using to read the samples? Are you using read or take?

fresh-ji commented 4 years ago

i am using “take”

捕获1

捕获2

fresh-ji commented 4 years ago

@Johnnyxy at https://github.com/ADLINK-IST/opensplice/issues/99 has solved my issue perfectly. Thanks for everyone.