Help: Using TelldusCore with Visual C++

Moderator: Telldus

Post Reply
Fable
Posts: 9
Joined: Fri Mar 17, 2023 9:45 am

Help: Using TelldusCore with Visual C++

Post by Fable »

I use the last version of Visual C++ and get these errors:

Code: Select all

error C3861: 'visibility': identifier not found	telldus-core.h	line: 47	1	Main
error C2448: '__attribute__' : function-style initializer appears to be a function definition	telldus-core.h	line: 47	1	Main
I downloaded the header from: http://developer.telldus.se/browser/tel ... dus-core.h (4 months old)
Running latest beta driver: 2.1.2_beta10

C2448 - http://msdn.microsoft.com/en-us/library/s611x42d.aspx
If MSDN is right it seems the syntax used in the header is outdated?

Code: Select all

#define TELLSTICK_API __attribute__ ((visibility("default")))
My code so far - just trying to get a link without errors:

Code: Select all

// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
//#include "C:\\Program Files (x86)\\Telldus\\TelldusCore.dll"
#include "windows.h"
#include "telldus-core.h"

using namespace std;

//int getNumberOfDevices();

int _tmain(int argc, _TCHAR* argv[])
{
	const wchar_t* dllPath = L"C:\\Program Files (x86)\\Telldus\\TelldusCore.dll";
	cout << "Initializing\n";
	HMODULE WINAPI tdCore = LoadLibrary(dllPath);
	if (!tdCore) {
		cout << "Unable to load TelldusCore.dll\n";
		return -1;
	}
	tdInit();
	//cout << getNumberOfDevices();
	//tdClose();
	return 0;
}

/*
int getNumberOfDevices() {
	int num = tdGetNumberOfDevices();
	return num;
}*/
I'm learning C++ so I usually have no idea what I'm talking about.

I wanted to try removing: __attribute__ ((visibility("default")))
It removed the error, but caused other errors of course.. not unexpected :)

Tellstick Duo is my motivation to learn another programming language. I'm really looking forward to making software with c++ for tellstick :)
Norwegian fan of Tellstick! Usually prefer speaking English especially when it comes to technical stuff :)
micke.prag
Site Admin
Posts: 2243
Joined: Fri Mar 17, 2023 9:45 am
Location: Lund
Contact:

Re: Help: Using TelldusCore with Visual C++

Post by micke.prag »

First, the visibility functions is only for gcc-platforms. Please make sure you have _WINDOWS defined so the correct macros are used.
Fable wrote:C2448 - http://msdn.microsoft.com/en-us/library/s611x42d.aspx
If MSDN is right it seems the syntax used in the header is outdated?
What functions? Lines?

Code: Select all

//#include "C:\\Program Files (x86)\\Telldus\\TelldusCore.dll"
You cannot include a binary file into c++ source.

Code: Select all

const wchar_t* dllPath = L"C:\\Program Files (x86)\\Telldus\\TelldusCore.dll";
   cout << "Initializing\n";
   HMODULE WINAPI tdCore = LoadLibrary(dllPath);
What is the reason to load the dll dynamically? This makes it much harder to use. Try linking it when compiling instead.

Code: Select all

tdInit();
Functions loaded dynamically cannot be called directly (at compile time). This is why I suggest you link instead of resolving the symbols during runtime.
Micke Prag
Software
Telldus Technologies
Fable
Posts: 9
Joined: Fri Mar 17, 2023 9:45 am

Re: Help: Using TelldusCore with Visual C++

Post by Fable »

micke.prag wrote:First, the visibility functions is only for gcc-platforms. Please make sure you have _WINDOWS defined so the correct macros are used.
Ah thank you :)
micke.prag wrote:
Fable wrote:C2448 - http://msdn.microsoft.com/en-us/library/s611x42d.aspx
If MSDN is right it seems the syntax used in the header is outdated?
What functions? Lines?
This one:

Code: Select all

#define TELLSTICK_API __attribute__ ((visibility("default")))
But as you mentioned I didn't define _WINDOWS so my bad :)
micke.prag wrote:

Code: Select all

//#include "C:\\Program Files (x86)\\Telldus\\TelldusCore.dll"
You cannot include a binary file into c++ source.
Yeah. That was a remnant of old :P
micke.prag wrote:

Code: Select all

const wchar_t* dllPath = L"C:\\Program Files (x86)\\Telldus\\TelldusCore.dll";
   cout << "Initializing\n";
   HMODULE WINAPI tdCore = LoadLibrary(dllPath);
What is the reason to load the dll dynamically? This makes it much harder to use. Try linking it when compiling instead.
I've been googling how to use DLL's. This was one way to do it that seems to work the best.
How do I link it when compiling?
micke.prag wrote:

Code: Select all

tdInit();
Functions loaded dynamically cannot be called directly (at compile time). This is why I suggest you link instead of resolving the symbols during runtime.

This sentence didn't make a lot of sense to me. Would you please mind explaining it? Specifically "instead of resolving the symbols during runtime"

I come from the land of PhP and worked as a professional web developer, but PhP doesn't even come close to C++. Which is why I want to learn it :)
I bought myself a book and gotten started, but I want to experiment with my own ideas while I do. Learning by doing works well for me - even though I am pretty sure I am in over my head trying to make something with the TelldusCore.dll this early.

Edit: I'm googling a bit now. Learning about symbols etc :)
Norwegian fan of Tellstick! Usually prefer speaking English especially when it comes to technical stuff :)
micke.prag
Site Admin
Posts: 2243
Joined: Fri Mar 17, 2023 9:45 am
Location: Lund
Contact:

Re: Help: Using TelldusCore with Visual C++

Post by micke.prag »

Fable wrote:This sentence didn't make a lot of sense to me. Would you please mind explaining it? Specifically "instead of resolving the symbols during runtime"
When the compiler runs it must know about every function used. This is what header files are for. This tells the compiler how to use the functions. When the compiler links your application it looks through your dll files and finds the functions you are using and adds them to your application (for you c++/compiler gurus, I know this is a oversimplification...). This makes it possible to use functions from dll-files as if they where created in your application. This is the normal and easiest way of using dll files.
The hard way is not letting your compiler know anything about the dll. When your application runs it loads the dll and investigate it while running. This code is much more complex and you often use this approach when building a plugin system. The application may not know of every plugin in compile time.
Fable wrote:How do I link it when compiling?
Hmm, this is the part I don't know in my head. We have this embedded in another build tool when we build our code. But I think the properties for the linking in your project has settings for what to link against. Normally in Windows you give the path to a *.lib file.

I hope this helps.
Micke Prag
Software
Telldus Technologies
Fable
Posts: 9
Joined: Fri Mar 17, 2023 9:45 am

Re: Help: Using TelldusCore with Visual C++

Post by Fable »

I'll include what I find in case there are other eager souls out there, like me :)

You need to fetch TelldusNETWrapper.dll, TelldusCore.lib, TelldusCore.dll and telldus-core.h from the "Development" folder (it is included when you install TelldusCenter).

Put those in your application folder.

Add this to your code:

Code: Select all

#define _WINDOWS
#include "telldus-core.h"
If you get an error saying the header file does not exist, then you have placed it in the wrong directory or you need to add a directory to your project. To do that: Right click your project in "Solution Explorer" and choose "Add"->"Reference"
Add the directory of your files to "configuration properties" -> "C/C++" -> "General" -> "Additional include directories"

Now you need to reference the files to your project.
In order for them to show up under "Common properties" -> "References" -> "Add reference" I had to do:
"Configuration properties" -> "General" -> "Common Language Runtime Support" -> "Common language runtime support (/clr)"

Now you can add the TelldusNETWrapper to your project under references. I tried adding the TelldusCore.dll instead, but that resulted in some errors among them saying it didn't have the proper .NET version.

Through the "Solution Explorer" I saw that the TelldusNETWrapper doesn't have the function tdInit(). So I tried skipping that.

---

And back to my problems :P

Now I am getting:

Code: Select all

error LNK2028: unresolved token (0A000474) "extern "C" void __stdcall tdInit(void)" (?tdInit@@$$J10YGXXZ) referenced in function "int __cdecl wmain(int,wchar_t * * const)" (?wmain@@$$HYAHHQAPA_W@Z)	D:\My documents\Visual C Projects\Telldus\Telldus\Telldus.obj	Telldus
So I am kinda stuck again.
This doesn't seem to be a "generic" problem. When I google "unresolved token extern c" there are a ton of different ways people have skrewed up :P
Norwegian fan of Tellstick! Usually prefer speaking English especially when it comes to technical stuff :)
micke.prag
Site Admin
Posts: 2243
Joined: Fri Mar 17, 2023 9:45 am
Location: Lund
Contact:

Re: Help: Using TelldusCore with Visual C++

Post by micke.prag »

Fable wrote:You need to fetch TelldusNETWrapper.dll, TelldusCore.lib, TelldusCore.dll and telldus-core.h from the "Development" folder (it is included when you install TelldusCenter).
TelldusNETWrapper.dll is not needed. Its only for .Net.
Fable wrote:Now you can add the TelldusNETWrapper to your project under references. I tried adding the TelldusCore.dll instead, but that resulted in some errors among them saying it didn't have the proper .NET version.
Do not add TelldusNETWrapper. This is still a C++ application. Add TelldusCore.lib instead.
Micke Prag
Software
Telldus Technologies
Fable
Posts: 9
Joined: Fri Mar 17, 2023 9:45 am

Re: Help: Using TelldusCore with Visual C++

Post by Fable »

MS VS Express 2013 says when I try to add the .lib or the .dll:

Could not add reference for one of these reasons:
- Targets a higher version of the .NET framework
- Not a .NET assembly
- Not a registered ActiveX control

I hope adding Common Language Runtime Support was correct? Without it the lib/dll are not listed at all.
Norwegian fan of Tellstick! Usually prefer speaking English especially when it comes to technical stuff :)
micke.prag
Site Admin
Posts: 2243
Joined: Fri Mar 17, 2023 9:45 am
Location: Lund
Contact:

Re: Help: Using TelldusCore with Visual C++

Post by micke.prag »

Fable wrote:I hope adding Common Language Runtime Support was correct
No, I only think this is for .Net or com-objects.
Look for the linker in the properties for the project (not the solution).
Micke Prag
Software
Telldus Technologies
Fable
Posts: 9
Joined: Fri Mar 17, 2023 9:45 am

Re: Help: Using TelldusCore with Visual C++

Post by Fable »

I've added TelldusCore.lib to the linker and removed everything from "References" and reset the CLR.

Code: Select all

error LNK2019: unresolved external symbol __imp__tdInit@0 referenced in function _wmain	D:\My documents\Visual C Projects\Telldus\Telldus\Telldus.obj	
error LNK1120: 1 unresolved externals	D:\My documents\Visual C Projects\Telldus\Debug\Telldus.exe	
Still getting unresolved symbols. I found some stack overflow threads that helped give me an inkling of what's wrong, but I'm struggling with applying that knowledge here.

http://stackoverflow.com/questions/3704 ... -but-shoul



My current code is extremely simple. To make things easier.

Code: Select all

// Telldus.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
#define _WINDOWS
#include "TelldusCore.h"


int _tmain(int argc, _TCHAR* argv[])
{

	tdInit();
	//std::cout << tdGetNumberOfDevices();
	
	return 0;
}
By the way - I really appreciate your help Micke :)
Trying my best to google and solve these answers on my own and as I said earlier I'm probably in way over my head, but the bright side is that I'm learning a lot regarding how things work.

Edit:
I prefer not using VC++ interface for development so I'm trying to use the VC++ compiler with my own texteditor etc.
Getting the same error with these compile options:

Code: Select all

cl /EHsc telldus.cpp /link /MACHINE:x86 core\TelldusCore.lib
Norwegian fan of Tellstick! Usually prefer speaking English especially when it comes to technical stuff :)
micke.prag
Site Admin
Posts: 2243
Joined: Fri Mar 17, 2023 9:45 am
Location: Lund
Contact:

Re: Help: Using TelldusCore with Visual C++

Post by micke.prag »

This is our configuration for TelldusCenter
tellduscorelib.png
tellduscorelib.png (67.65 KiB) Viewed 27465 times
Micke Prag
Software
Telldus Technologies
micke.prag
Site Admin
Posts: 2243
Joined: Fri Mar 17, 2023 9:45 am
Location: Lund
Contact:

Re: Help: Using TelldusCore with Visual C++

Post by micke.prag »

Another thing, is your Windows 64 bit or 32 bit?
Micke Prag
Software
Telldus Technologies
Fable
Posts: 9
Joined: Fri Mar 17, 2023 9:45 am

Re: Help: Using TelldusCore with Visual C++

Post by Fable »

Running 64bit win7. But application was set to Win32.
Norwegian fan of Tellstick! Usually prefer speaking English especially when it comes to technical stuff :)
micke.prag
Site Admin
Posts: 2243
Joined: Fri Mar 17, 2023 9:45 am
Location: Lund
Contact:

Re: Help: Using TelldusCore with Visual C++

Post by micke.prag »

When you install TelldusCenter on 64 bit the 64-bit TelldusCore.lib is also installed. Try to compile your application as 64-bit instead.
Micke Prag
Software
Telldus Technologies
Fable
Posts: 9
Joined: Fri Mar 17, 2023 9:45 am

Re: Help: Using TelldusCore with Visual C++

Post by Fable »

It works!!! Thank you so much Micke <3
Norwegian fan of Tellstick! Usually prefer speaking English especially when it comes to technical stuff :)
Post Reply