OPC and VC++ (not .net)

B

Thread Starter

Brain21

Hi, I am trying to communicate with the "OPCDAAuto.dll" DLL. I know it works in VB. I recently came across some VC++ code that would load a COM object and be able to interface to it. I have tried with my own made VB COM object, but when I try with this dll I get some errors. I've registered the dll and can't get it to work. Has any tried or gotten this to work? Is there another way? I don't have .Net (anything .Net that is). I'd like to get it to work for VC++ 6.0. This is the code that I have:

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

# import "OPCDAAuto.dll"
using namespace OPCAutomation;


int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
HRESULT hresult;
CLSID clsid;
char buffer[ 100 ];

hresult = CoInitialize(NULL);
if ( FAILED( hresult ) )
{
sprintf( buffer, "Cannot Initiate COM: Error %u", hresult );
MessageBox( NULL, buffer, "Error", MB_OK );
return 1;
}

hresult=CLSIDFromProgID(OLESTR("OPCAutomation.OPCGroups"),&clsid);
if ( FAILED( hresult ) )
{
sprintf( buffer, "Invalid ID: Error %u", hresult );
MessageBox( NULL, buffer, "Error", MB_OK );
}


IOPCGroups *t;
hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(IOPCGroups),(LPVOID *) &t);
if ( FAILED( hresult ) )
{
sprintf( buffer, "Creation Failed: Error %u", hresult );
MessageBox( NULL, buffer, "Error", MB_OK );
return 2;
}


t->Release ();
CoUninitialize();



return 0;
}

I am getting the ID Failed error and the Creation Failed one too.

Brain21
 
Hi,

I don't even know whether you have solved your problem--However, I have met the same problem like yours. You can replace the connection part of your code with the code below:

_bstr_t strServerBack=_bstr_t("S7200.OPCServer");
MyOPCServer.CreateInstance(__uuidof(OPCServer));
MyOPCServer->Connect(strServerBack);

//That's enough, but you should register your sopcautoda.dll before your action. I am doing some research in this area, I think we can keep in touch by email for our further study.
 
Top