B
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
#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