Trouble using a DLL with ROOT

Dear ROOT Devs,

I have a problem relating to ROOT with Windows DLLs. My ROOT version is Version 5.19/02

I have a program which performs some socket communication written in C++. I have written the necessary wrappers for this to use with ROOT and everything works fine in Linux.

Recently I have converted this C++ program to Windows environments and it is working fine as a normal DLL.

I tried to use the DLL with ROOT (in Windows) but could not get it working.

I track down the problem and now it has reduced to a something like below.

I have this simple test method in my class

class  TUtils :public TObject
{
			
	public:
	    TUtils();
	    virtual ~TUtils();
	    void TestMethod(string msg);
}

The implementation of this method is as follows

void TUtils::TestMethod(string msg){
	cout<<"Printing from TUtils: "<<msg<<endl;
}

I generated the dictionary for this class using root-cint as follows.

I include the dictionary and the code in to my DLL (I used Visual Studio V 9.0) and compile it.

I used the CINT interpreter to load the DLL and then try to call this method.

What i see as the output is the following.

The string parameter is not passed correctly to the method call. Probably something to do with the STL and ROOT.

Could someone please help me to figure this out.

Thanks,
Jaliya

Hi Jaliya,

I have no problem with your code:

C:\Users\bellenot\rootdev\TUtils>root -l root [0] gSystem->Load("libTUtils") (int)0 root [1] TUtils tu; root [2] tu.TestMethod("ABC"); Printing from TUtils: ABC root [3]
How did you build your dll?

Cheers, Bertrand.

Hi Bertrand,

Thanks for the quick reply.

I used Visual studio editor to build the dll.

I have used the $ROOT_HOME/include directory for the headers and used libCore.lib and libCint.lib for linking.

Also have the /FIw32pragma.h flag as mentioned here.
root.cern.ch/phpBB2/viewtopic.ph … bc578c4c5e

Probably I am missing some configuration option.

In my class definition, I did not use the dllexport flag because it causes errors when I generate the dictionary.

Could you please let me know the command line you used to create the dll?

Thanks,
Jaliya

Hi

I use makefile on cygwin, but I can prepare a project file. Just tell me which version of Visual Studio you are using. Or I can also make a nmake makefile… Just let me know what you prefer.

Cheers,
Bertrand.

Hi Bertrand,

I am using Visual Studio 2008 Version 9.0.2xx.

Could you please prepare an nmake file for me. This will help me to figure out the command options.

Thanks,
Jaliya

Hi Jaliya,

Here is the makefile. Just rename the file (i.e Makefile.msc) and type “nmake -f Makefile.msc” it should work (just check the file names).
And please let me know if you have any problem…

Cheers,
Bertrand.
Makefile.txt (4 KB)

Just in case, here is the full code. Extract it somewhere, Then:
cd TestUtils
nmake -f Makefile.msc
It should work.

Cheers,
Bertrand.
TestUtils.tar.gz (1.77 KB)

Hi Bertrand

Thank you very much for the help.

I tried the dll but still I am not seeing the string parameter I pass to the method call. I get the following.

D:\Projects\VS2008\TestUtils\TestUtils>root -l root [0] {gSystem->Load("libTUtils.dll"); TUtils tu; tu.TestMethod("ABCD");} Printing from TUtils: root [1]

(I used the tar file that you have sent, and created the dll using nmake)

Is it something to do with my ROOT version? (I use ROOT Version 5.19/02)

Thanks,
Jaliya

Hi Jaliya,

I’m using svn trunk… I’ll try with version 5.19.02 tomorrow and I’ll let you know.

Cheers,
Bertrand.

Sure, Thank you very much.
Jaliya

Hi Jaliya,

I just tried with 5.19.02 binaries, and I see the problem… So apparently this has been solved since then. And as the version 5.19.04 should be available tomorrow, just wait a bit and your problem will be solved :wink:
(and the MSVC++ 9.0 binaries will be available too! :smiley:)

Cheers,
Bertrand.

I even tried, Version 5.18 and found that the same problem is there too.

I will download the latest version and try it tomorrow.
Thank you very much for the help Bertrand!

-Jaliya

Hi Bertrand,

I tried the simple program with ROOT version 5.19.04 but still I am experiencing the same problem.

Probably the fix has not been included in this release.

Currently only the VC++ 7.1 download link is working. So I used that one.

Thanks,
Jaliya

Hi Jaliya,

The MSVC++9.0 version of Root will be available tomorrow (sorry for the delay)

Cheers,
Bertrand.

Hi Bertrand,
Sure, I will check it tomorrow :slight_smile:
Thanks,
Jaliya

Hi Bertrand,

I tried the new binaries with the simple program.
Now it is printing only a portion of the string.

I called the TUtils as follows.

TUtils tu; tu.TestMethod("ABCDEFGH");

and the results is

I even tried the instructions given below the releases to replace the iostream.h with Riostream.h but still it is the same. Please help.

Thanks,
Jaliya

Hi Jaliya,
Sorry, but it works just fine for me:

C:\Users\bellenot\rootdev\TestUtils>root -l root [0] gSystem->Load("libTUtils.dll"); root [1] TUtils tu; root [2] tu.TestMethod("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"); Printing from TUtils: ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 root [3]
Cheers,
Bertrand.

Hi Bertrand,

I am sorry to trouble you again on this issue.

I tried the sample on two different machines, but what I am getting is some garbage characters.

root [0] gSystem->Load("libTUtils.dll"); root [1] TUtils tu; root [2] tu.TestMethod("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"); Printing from TUtils: ☼ TUti$ / ♣ ♣ τ☺♀♥

I use the nmake file you sent to create the DLL. I also tried a DLL created by the Visual studio editor.

Probably I have missed some minute configuration.

Thanks,
Jaliya

OK, I will try to reproduce the problem and I’ll let you know.
Cheers, Bertrand.

OK, I see the problem… It works only in debug mode and fails in Release (optimized) mode :frowning: It is maybe due to the way Micro$oft implement STL… I will investigate and let you know.

Cheers, Bertrand