TM1 C++ API issue

TrevorGoss
Community Contributor
Posts: 217
Joined: Thu Aug 15, 2013 9:05 am
OLAP Product: TM1
Version: 10.2.1.1
Excel Version: 14.0.6129.5000

TM1 C++ API issue

Post by TrevorGoss »

Hello to all,

I am trying to start the TM1 API for c++.

I am using Visual Studio 2010.

I have the header files included and the paths set in Visual Studio.

I have also set the PATH enviroment variable to the path of the header and .lib files.

But when I run my program, after a successful build, it gives me a System Error telling me that "The program can't start because TM1API.dll is missing from your computer. Try reinstalling the program to fix this problem"

I am sure the PATH enviroment variable is set, because when I run the command set "Path" I am given a return value of the PATH variable with the relevant TM1 links in there.

Has anybody come across this before? An error telling you that a dll is missing from visual studio c++?

As far as I am aware I have followed the documentation to the letter.

I am on TM1 10.2.1, on Windows.

Thanks.

Trevor
BrianL
MVP
Posts: 264
Joined: Mon Nov 03, 2014 8:23 pm
OLAP Product: TM1
Version: 9.5.2 10.1 10.2 PA2
Excel Version: 2016

Re: TM1 C++ API issue

Post by BrianL »

TrevorGoss wrote:I am trying to start the TM1 API for c++.
Just so you know, IBM has been pushing their new REST api recently instead of the C api, but YMMV.

As for your actual question, if you're trying to run your program from inside Visual Studio (debug, etc...) you'll need to make sure Visual Studio itself is running with the path set correctly. If this is the case but you're still struggling, Process Explorer (from microsoft) is capable of displaying the environment settings of any running program.

If you're not trying to run your program from inside Visual Studio, you can try the free Dependency Walker tool. This used to be shipped with VS 2005 and earlier.
TrevorGoss
Community Contributor
Posts: 217
Joined: Thu Aug 15, 2013 9:05 am
OLAP Product: TM1
Version: 10.2.1.1
Excel Version: 14.0.6129.5000

Re: TM1 C++ API issue

Post by TrevorGoss »

Just so you know, IBM has been pushing their new REST api recently instead of the C api, but YMMV.
Indeed, I just could not find any place to start when it came to the REST api, the documentation seemed weaker for REST than it did for the c++ and Java api. Any links will be most appreciated.

As for your actual question, if you're trying to run your program from inside Visual Studio (debug, etc...) you'll need to make sure Visual Studio itself is running with the path set correctly. If this is the case but you're still struggling, Process Explorer (from microsoft) is capable of displaying the environment settings of any running program.

If you're not trying to run your program from inside Visual Studio, you can try the free Dependency Walker tool. This used to be shipped with VS 2005 and earlier.
I have managed to get it loaded now and I can run the functions in c++ for the TM1 api. It was rather strange, I had to bring across 4 dlls from the TM1 bin folder and palce them in the same directory as the exe file. VS kept telling me that a dll was missing, so I picked it from the TM1 folder and placed it in, after about 4 dll moves it worked.

The issue I have now is that it will not find any admin servers, even though I am passing it the machine name. the code:

Code: Select all

TM1U		hUser = 0;
	TM1_INDEX	iServerCount;
	TM1_INDEX	iServer;
	CHAR		* sDbName;
	TM1V		voDbHandle;

	hUser = TM1SystemOpen();
	std::cout << hUser << std::endl;
	if(hUser)
	{
		
		//printf("you are in the first if"); // to test the if
		TM1SystemAdminHostSet(hUser,"ABCDE12345");

		iServerCount = TM1SystemServerNof( hUser);
		std::cout << iServerCount << std::endl;
		for (iServer = 1; iServer <= iServerCount; iServer++)
		{
			sDbName = TM1SystemServerName(hUser,iServer);

			voDbHandle = TM1SystemServerHandle(hUser, sDbName);
			
			if( voDbHandle)
			{
				std::cout << "CONNECTED:\t" << sDbName << std::endl;
			}else
			{
				std::cout << "NOT CONNECTED:\t" << sDbName << std::endl;
			}
		}

		TM1SystemClose( hUser );
	}
	else
	{
		std::cout << "Cannot connect to the API" <<std::endl;
	}
Is trying to print out al lthe TM1 services inside the passed machine "ABCDE12345", but it returns nothing...

Any ideas? Thanks Brian.

Trevor.
User avatar
Alan Kirk
Site Admin
Posts: 6606
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: TM1 C++ API issue

Post by Alan Kirk »

TrevorGoss wrote:
Brian L wrote:Just so you know, IBM has been pushing their new REST api recently instead of the C api, but YMMV.
Indeed, I just could not find any place to start when it came to the REST api, the documentation seemed weaker for REST than it did for the c++ and Java api. Any links will be most appreciated.
Just so you also know, I saw the REST API at the Cubewise Conference last week and it Rocks. Like. Hell. I've been having dreams about it ever since. Which is kinda sad when you think about it. And getting it to do some stuff is on my to do as soon as is possible list, though of course this is mitigated by the fact that we still have a chunk of our system on 9.5.2 and I have to get that over first.

But just so you also also know, yes, there is indeed a paucity of documentation on it. This actually came up at the conference with someone asking a question on that, and the answer was that (a) there was stuff on Developerworks (which there is, but just disjointed fragments here and there) and (b) It is oData compliant and there is plenty of stuff out there on that. (Here, for example.) But make no mistake, the REST API is going to be a much steeper learning curve than any of the older APIs were, and also {sotto voce} there may be the odd bug in it given that it's an early release. But in terms of raw freaking power and speed, that thing looks to be The Business.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
TrevorGoss
Community Contributor
Posts: 217
Joined: Thu Aug 15, 2013 9:05 am
OLAP Product: TM1
Version: 10.2.1.1
Excel Version: 14.0.6129.5000

Re: TM1 C++ API issue

Post by TrevorGoss »

Just so you also know, I saw the REST API at the Cubewise Conference last week and it Rocks. Like. Hell.
I also have heard good things about it, which is why I want to find out more, plus...c++ gives me a headache lol.

Thanks for the links I will investigate and use the tutorials.

Trevor
User avatar
Alan Kirk
Site Admin
Posts: 6606
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: TM1 C++ API issue

Post by Alan Kirk »

TrevorGoss wrote:
Just so you also know, I saw the REST API at the Cubewise Conference last week and it Rocks. Like. Hell.
I also have heard good things about it, which is why I want to find out more, plus...c++ gives me a headache lol.

Thanks for the links I will investigate and use the tutorials.
No problem. Something else that you may find useful - I saw it being used in the demonstrations but haven't downloaded it myself yet - is the Postman tool which can be found here.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
TrevorGoss
Community Contributor
Posts: 217
Joined: Thu Aug 15, 2013 9:05 am
OLAP Product: TM1
Version: 10.2.1.1
Excel Version: 14.0.6129.5000

Re: TM1 C++ API issue

Post by TrevorGoss »

No problem. Something else that you may find useful - I saw it being used in the demonstrations but haven't downloaded it myself yet - is the Postman tool which can be found here.
Thanks
BrianL
MVP
Posts: 264
Joined: Mon Nov 03, 2014 8:23 pm
OLAP Product: TM1
Version: 9.5.2 10.1 10.2 PA2
Excel Version: 2016

Re: TM1 C++ API issue

Post by BrianL »

TrevorGoss wrote: The issue I have now is that it will not find any admin servers, even though I am passing it the machine name.
This can often be caused by an SSL error. If you haven't yet, try copying the entire "ssl" folder from the TM1 bin directory into the same place as the dlls (or try disabling SSL on BOTH admin server and tm1 server).
TrevorGoss
Community Contributor
Posts: 217
Joined: Thu Aug 15, 2013 9:05 am
OLAP Product: TM1
Version: 10.2.1.1
Excel Version: 14.0.6129.5000

Re: TM1 C++ API issue

Post by TrevorGoss »

This can often be caused by an SSL error. If you haven't yet, try copying the entire "ssl" folder from the TM1 bin directory into the same place as the dlls
That worked, excellent thanks.

Have you ever connected to a TM1 server with this API?

My code:

Code: Select all

TM1SystemAdminHostSet(hUser,"ABCDE12345");

		iServerCount = TM1SystemServerNof( hUser);
		std::cout << iServerCount << std::endl;
		for (iServer = 1; iServer <= iServerCount; iServer++)
		{
			sDbName = TM1SystemServerName(hUser,iServer);
			voDbHandle = TM1SystemServerHandle(hUser, sDbName);
			std::cout << voDbHandle << std::endl;
			if( voDbHandle)
			{
				std::cout << "CONNECTED:\t" << sDbName << std::endl;
			}else
			{
				std::cout << "NOT CONNECTED:\t" << sDbName << std::endl;
			}
		}

		TM1SystemClose( hUser );
Is always returning

Code: Select all

std::cout << "NOT CONNECTED:\t" << sDbName << std::endl;
So it is not connecting to the TM1 servers, any ideas?

Thanks Brian.

Trevor
BrianL
MVP
Posts: 264
Joined: Mon Nov 03, 2014 8:23 pm
OLAP Product: TM1
Version: 9.5.2 10.1 10.2 PA2
Excel Version: 2016

Re: TM1 C++ API issue

Post by BrianL »

TrevorGoss wrote:So it is not connecting to the TM1 servers, any ideas?r
Unless I'm missing some code, you haven't actually attempted to connect (log in) to the server. You'll only get a handle back from TM1SystemServerHandle if you've already logged in. For the C API, log in and connect are pretty much synonymous.
TrevorGoss
Community Contributor
Posts: 217
Joined: Thu Aug 15, 2013 9:05 am
OLAP Product: TM1
Version: 10.2.1.1
Excel Version: 14.0.6129.5000

Re: TM1 C++ API issue

Post by TrevorGoss »

Hello again Brian, thanks for the reply.
Unless I'm missing some code, you haven't actually attempted to connect (log in) to the server. You'll only get a handle back from TM1SystemServerHandle if you've already logged in.
I would think this code:

Code: Select all

		for( iServer = 1; iServer <= iServerCount; iServer++)
		{
			sDbName = TM1SystemServerName( hUser, iServer );
			voDbHandle = TM1SystemServerHandle( hUser, sDbName );
			if ( voDbHandle ){
					std::cout << "Connected: " << sDbName << std::endl;
			}else{
					std::cout << "Not Connected: " << sDbName << std::endl; 
			}
		}

		TM1SystemClose( hUser );
Was trying to connect (login) to the server, I have a handle call and then an if statement checking if handle is true (connected), is there anything else required?

By the way, my source for this code was the file "GetListofServers.cpp" in the samplecode/cpp fodlers of the tm1api path.

My servers are also on run state 5, if this makes a difference.

Thanks.
tomok
MVP
Posts: 2831
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: TM1 C++ API issue

Post by tomok »

Where is the code for logging in? The example you used just get's a list of available servers, it doesn't actually log in. You have to log in with a call to the TM1SystemServerConnect function. A quick Google search returned this link: http://www-01.ibm.com/support/knowledge ... inC_N700AA
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
TrevorGoss
Community Contributor
Posts: 217
Joined: Thu Aug 15, 2013 9:05 am
OLAP Product: TM1
Version: 10.2.1.1
Excel Version: 14.0.6129.5000

Re: TM1 C++ API issue

Post by TrevorGoss »

Hello Tom, thanks for the response.

I have copied the code from that link in a new function and it returns no errors, but I am not sure if it was successful, my code:

Code: Select all

char * sAdminHost = "ABCDE12345";
	TM1SystemAdminHostSet (hUser,(CHAR *) sAdminHost);
//
// Create Value Pools from strings so that we can log in.
//
	hPool1 = TM1ValPoolCreate(hUser);
	hPool2 = TM1ValPoolCreate(hUser);
	char * sUserName = "a";
	char * sServerName = "Server";
	char * sPassword = "";
	TM1V vUserName = TM1ValString(hPool1, (CHAR *) sUserName, 10);
	TM1V vServerName = TM1ValString(hPool1, (CHAR *) sServerName, 10);
	TM1V vPassword = TM1ValString(hPool1, (CHAR *) sPassword, 10);
//
// TM1SystemServerConnect logs in to TM1. This function returns
// a TM1 server object
//
	TM1V vServerObject = TM1SystemServerConnect(hPool1, vServerName,
	vUserName, vPassword);
	TM1V vsServerName = TM1ObjectPropertyGet (hPool2, vServerObject, TM1ObjectName()
	);
	sServerName = (char *) TM1ValStringGet(hUser, vsServerName);
	if(vServerObject)
	{
		std::cout << "yes" << std::endl;
	}
The last bit of code is to check if I have connected, I was hoping that if the vServerObject is true, I have connected and I do receive a "yes" when the code is run.

Is it also possible to log into runstate 5? The documentation only (AFAIK) talks about run state 1,2 or 3.

Thanks.
TrevorGoss
Community Contributor
Posts: 217
Joined: Thu Aug 15, 2013 9:05 am
OLAP Product: TM1
Version: 10.2.1.1
Excel Version: 14.0.6129.5000

Re: TM1 C++ API issue

Post by TrevorGoss »

Success!

I created code that gets the handle of the user and the server and then I test its connection:

Code: Select all

	voDbHandle = TM1SystemServerHandle( hUser, sServerName );

	if ( voDbHandle ){
					std::cout << "Connected: " << sServerName << std::endl;
			}else{
					std::cout << "Not Connected: " << sServerName << std::endl; 
			}
Add this code to the bottom of my previous code and I will receive a "Connected" message to the screen, if I put a server name that does not exist, it fails, so some success.

I would still like to know if I can connect to TM1 servers in run state 5?

Thanks
BrianL
MVP
Posts: 264
Joined: Mon Nov 03, 2014 8:23 pm
OLAP Product: TM1
Version: 9.5.2 10.1 10.2 PA2
Excel Version: 2016

Re: TM1 C++ API issue

Post by BrianL »

The function is not documented for CAM login, but the following code should work.

(Note: you can find the function declaration in TM1API.H. This can be a good source of undocumented function names for the C API. The declaration doesn't explain what all the params are, but sometimes a little trial and error can go a long way.)

Code: Select all

TM1V vArray[3];
TM1V vCAMarr;

char * sServerName = "Server";
TM1V vServerName = TM1ValString(hPool1, (CHAR *) sServerName, 0);

vArray[0] = TM1ValString(hPool1, (char*)sCAMNamespace, 0 );
vArray[1] = TM1ValString(hPool1, (char*)sUsername, 0 );
vArray[2] = TM1ValStringEncrypt(hPool1, (char*)sPassword, 0 );
vCAMarr = TM1ValArray( hPool1, vArray, 3 );

TM1V vServerObject = SystemServerConnectWithCAMNamespace(hPool1, vServerName, vCAMarr );
TrevorGoss
Community Contributor
Posts: 217
Joined: Thu Aug 15, 2013 9:05 am
OLAP Product: TM1
Version: 10.2.1.1
Excel Version: 14.0.6129.5000

Re: TM1 C++ API issue

Post by TrevorGoss »

I have got it working with CAM now thanks.
(Note: you can find the function declaration in TM1API.H. This can be a good source of undocumented function names for the C API. The declaration doesn't explain what all the params are, but sometimes a little trial and error can go a long way.)
Good idea, the intellisense can be helpful for undocumented functions aswell.

Thanks for your help, are there any "gotchas" or any other dodgy things that can come out of the C/C++ api?

Trevor.
BrianL
MVP
Posts: 264
Joined: Mon Nov 03, 2014 8:23 pm
OLAP Product: TM1
Version: 9.5.2 10.1 10.2 PA2
Excel Version: 2016

Re: TM1 C++ API issue

Post by BrianL »

There are a couple counter-intuitive quirks of the API that are documented.

http://www-01.ibm.com/support/knowledge ... ety_N704C3
This one is basically saying if you share user handles (gotten from SystemServerConnect) across multiple threads, the API will serialize the calls and only run one at a time.

http://www-01.ibm.com/support/knowledge ... ues_N707C7
This one is trickier to understand. Essentially the API will queue up all network traffic until you actually query the type or contents of a TM1V. Until then, the API will transparently queue up any requested API calls and send them to the server all at once. Even using return values from one function as a parameter to the next can be handled in a single network round trip (as long as you don't query the type or contents of the return value first).

That's all that comes to mind off the top of my head.
TrevorGoss
Community Contributor
Posts: 217
Joined: Thu Aug 15, 2013 9:05 am
OLAP Product: TM1
Version: 10.2.1.1
Excel Version: 14.0.6129.5000

Re: TM1 C++ API issue

Post by TrevorGoss »

There are a couple counter-intuitive quirks of the API that are documented.

http://www-01.ibm.com/support/knowledge ... ety_N704C3
This one is basically saying if you share user handles (gotten from SystemServerConnect) across multiple threads, the API will serialize the calls and only run one at a time.

http://www-01.ibm.com/support/knowledge ... ues_N707C7
This one is trickier to understand. Essentially the API will queue up all network traffic until you actually query the type or contents of a TM1V. Until then, the API will transparently queue up any requested API calls and send them to the server all at once. Even using return values from one function as a parameter to the next can be handled in a single network round trip (as long as you don't query the type or contents of the return value first).

That's all that comes to mind off the top of my head.
Thanks for these, I have managed to connect to the API which is what I wanted, now the rest is up to me and playing around.

Thanks.
TrevorGoss
Community Contributor
Posts: 217
Joined: Thu Aug 15, 2013 9:05 am
OLAP Product: TM1
Version: 10.2.1.1
Excel Version: 14.0.6129.5000

Re: TM1 C++ API issue

Post by TrevorGoss »

Hello again,

I thought I would post this question here rather than start a new post because of the topic.

I am trying to run a TI process via the C++ API, using the function TM1ProcessExecute. The TI I am using is just a flat file creation to test it.

My issue is that the TI takes no parameters, so the IBM documentation states
A process with no parameters takes an array of zero elements
but, in c++ (as far as I am aware) you cannot have array sizes of nothing, i.e. zero elements, so I do not see how I can fire this TI?

Has anyone fired a TI via the c++ API before? Did they come across this function? Does anyone have and ideas how to get past this issue?

Thanks.

Trevor.
BrianL
MVP
Posts: 264
Joined: Mon Nov 03, 2014 8:23 pm
OLAP Product: TM1
Version: 9.5.2 10.1 10.2 PA2
Excel Version: 2016

Re: TM1 C++ API issue

Post by BrianL »

The API is looking for a TM1V, not a C array. Thus you should be able to do something like

Code: Select all

TM1V empty;
TM1V params = TM1ValArray(pool, empty, 0);
TM1ProcessExecuteEx(pool, process, params );
Post Reply