Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Compiling with Visual Studio 2013 Express

More
08 May 2014 09:03 - 08 May 2014 09:04 #1951 by support
I have given it a try. Here is what I did:
  1. Took a new Windows 7 installation.
  2. Installed "Microsoft Visual Studio Express 2013 for Windows Desktop".
  3. Installed latest QuickOPC 5.30, custom->full installation ("for COM development" should be sufficient, too).
  4. Opened the solution with COM-based C++ examples: Start -> All Programs -> OPC Labs -> QuickOPC 5.3 -> Examples (Source Code) -> COM Visual C++ Examples.
  5. Visual Studio auto-upgrades the projects (we intentionally provide them in VS 2012 format).
  6. Build the solution. It has 5 projects, 4 of them will fail, because they use either MFC or ATL, and these are not supported under the VS "Express" Edition.

The project that builds well (and it actually also runs) is the DumpAddressSpace. Here is the relevant code:
// $Header: $
// Copyright (c) CODE Consulting and Development, s.r.o., Plzen. All rights reserved.
// DumpAddressSpace.cpp : Defines the entry point for the console application.
// Dumps OPC server's address space recursively to the console.
//
#include "stdafx.h"
 
#import "libid:FAB7A1E3-3B79-4292-9C3A-DF39A6F65EC1" version(5.2)	// EasyOpcLib
#import "scrrun.dll" rename("DeleteFile", "DeleteFileX") rename("MoveFile", "MoveFileX") rename("CopyFile", "CopyFileX") \
	exclude("IDrive", "IDriveCollection", "IFileSystem", "IFileSystem3", "IFolder", "ITextStream", "IFolderCollection", "IFile", \
		"IFileCollection")
 
using namespace EasyOpcLib;
using namespace Scripting;
 
//
 
void DumpBranch(IEasyDAClientPtr EasyDAClientPtr, LPCTSTR ParentItemId, int Level)
{
	// Browse all nodes (branches and leaves) under ParentItemId
	IDictionaryPtr NodeElementDictionaryPtr(EasyDAClientPtr->BrowseNodes(_T(""), _T("OPCLabs.KitServer.2"), ParentItemId));
	variant_t vKeys(NodeElementDictionaryPtr->Keys());
	variant_t vItems(NodeElementDictionaryPtr->Items());
 
	LONG Ubound;
	SafeArrayGetUBound(vKeys.parray, 1, &Ubound);
	for (LONG i = 0; i <= Ubound; i++)
	{
		_variant_t vKey;
		SafeArrayGetElement(vKeys.parray, &i, &vKey);
		_variant_t vItem;
		SafeArrayGetElement(vItems.parray, &i, &vItem);
		IDANodeElementPtr NodeElementPtr(vItem);
 
		for (int j = 0; j < Level; j++) _tprintf(_T("    "));
		_tprintf(_T("'%s': HasChildren %d, IsBranch %d, IsLeaf %d, ItemId '%s', Name '%s'\n"), 
			(TCHAR*)_bstr_t(vKey),
			NodeElementPtr->HasChildren, 
			NodeElementPtr->IsBranch, 
			NodeElementPtr->IsLeaf, 
			(TCHAR*)NodeElementPtr->ItemId, 
			(TCHAR*)NodeElementPtr->Name);
 
		// If this node is a branch, dump its children recursively
		if (NodeElementPtr->IsBranch)
			DumpBranch(EasyDAClientPtr, NodeElementPtr->ItemId, Level + 1);
	}
}
 
int _tmain(int argc, _TCHAR* argv[])
{
	// Initialize the COM library
	CoInitialize(NULL);
 
	// Instatiate the EasyOPC-DA client object
	IEasyDAClientPtr EasyDAClientPtr(__uuidof(EasyDAClient));
	// Dump the OPC address space from the root branch
	DumpBranch(EasyDAClientPtr, _T(""), 0);
	// Release all interface pointers BEFORE calling CoUninitialize()
	EasyDAClientPtr = NULL;
 
	CoUninitialize();
 
	TCHAR line[80];
	_putts(_T("Press Enter to continue..."));
	_fgetts(line, sizeof(line), stdin);
	return 0;
}
 

This project uses what is called I think "native compiler support" for COM, i.e. it has its own version of smart pointer classes etc. (different from ATL or COM), and it is capable of "importing" the type library and creating the C++ definitions of interfaces and classes.

This approach should work pretty well as long as you are just calling methods. It will probably get a bit complicated or problematic once you need to set up events (for notifications - subscriptions).

Let me know if you need more help in this area, such as providing example for reading, writing etc.
Last edit: 08 May 2014 09:04 by support. Reason: typo corr.

Please Log in or Create an account to join the conversation.

More
07 May 2014 12:04 #1937 by dlbrown06

Please Log in or Create an account to join the conversation.

More
07 May 2014 12:03 #1936 by support
We do not officially support the Express editions of Visual Studio, but we are getting occasional reports that parts of our stuff works - or does not work.

I will try to make the example you mentioned, for VS 2013 Express, and send it to you. Please allow a day or several days before I have the results.

Best regards

Please Log in or Create an account to join the conversation.

More
06 May 2014 20:26 #1931 by dlbrown06
Hopefully this is a simple question, but are there any projects that are simple to the point where they only read an item and display it in the command line interface using Visual Studio C++ 2013 Express?

I'm having difficulty compiling and running somethere that I would hope to be very simple. It's important to note that I'm experienced with c++ but not so much with Visual Studio.

Few issues are where is the libid is found when importing the com object to the project? I guess that would help me get started.

Thanks!

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.058 seconds