HI

I want to create an Instance of Class(Object) In Visual Basic.Using "Create Object " Syntax. please refer attached CPP & header File for the class COMOutput. How can i create an object for this COMOutput Class in Visual Basic. And I need to access the Functions Defined in The COMOutput.Cpp. PLease Help me.Thanks

Augustin

Attachments
//////////////////////////////////////////////////////////////////////////////////////////
// COMOutput.cpp
//
//
// Description:
//
// This is the implementation of the COMOutput COM class.  It allows the CGProbe objects
// to call the Print functions in the application's dialog
//////////////////////////////////////////////////////////////////////////////////////////


#include "stdafx.h"
#include "COMOutput.h"
#include "resource.h"
#include "SampleAppDlg.h"

STDMETHODIMP COMOutput::raw_Print(BSTR msg)
{
	if ( _output != NULL ) {
		_output->Print( _bstr_t( msg ) );
	}
	return S_OK;
}

STDMETHODIMP COMOutput::raw_PrintLn(BSTR msg)
{
	if ( _output != NULL ) {
		_output->PrintLn( _bstr_t( msg ) );
	}
	return S_OK;
}
//////////////////////////////////////////////////////////////////////////////////////////
// COMOutput.h
//
//
// Description:
//
// This is the definition of a COM class used for linking the dialog to the CGProbe classes
// in order to get output from the firmware.  This object simply sets a variable ( _output )
// to the current dialog (in this case CSampleAppDlg) and calls the implemented Print() and
// PrintLn() from it's raw_Print() and raw_PrintLn()
//////////////////////////////////////////////////////////////////////////////////////////



#if !defined( GProbeUI_COMOutput_H )
#define GProbeUI_COMOutput_H

class CSampleAppDlg;

class COMOutput :
	public CComObjectRoot,
	public IDispatchImpl<ITerminal, &IID_ITerminal, &LIBID_CGPROBELib>
{
public:
	COMOutput() : _output( NULL ) {}

	void outputctrl( CSampleAppDlg* output ) { _output = output; }

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	BEGIN_COM_MAP(COMOutput)
		COM_INTERFACE_ENTRY(ITerminal)
		COM_INTERFACE_ENTRY(IDispatch)
	END_COM_MAP()

	// ITerminal
	public:
		STDMETHOD(raw_PrintLn)(BSTR msg);
		STDMETHOD(raw_Print)(BSTR msg);

	private:
		CSampleAppDlg *_output;
};


#endif

You need to compile this cpp class as a .DLL and then refer this dll in your VB propject.

You are good to go.

Create a dll file using VC++ Win32 Dynamic-Link Library Project type.
Compile the dll and register it in system32.

Hi Binoj

I have tried to create a DLL with the C++ & the Header file. But i got Errors While Creating . As i have No idea on What Header Files to be included for the Errors. Can u help me on that

.CPP and .H files can't be directly referenced fronm VB. compile to .DLL file and then instanceate in VB.

HI debasis,

I have tried to create a DLL with the C++ & the Header file. But i got Errors While Creating . As i have No idea on What Header Files to be included for the Errors. Can u help me on that ..please try to create a DLL with the files i have attached & can u give me a feedback on Errors....Thanks

create a DLL.register
to to command prompt and type
c:>regsvr32 <complete path of DLL>

open your vb project. go to project-refrences- add the DLL from the list

now create a object
dim obj as new <nameof DLL.ClassName>

now u can use the function

hope this will work

.CPP and .H files can't be directly referenced fronm VB. compile to .DLL file and then instanceate in VB.

Please see the post before you post redundant replies.

create a DLL.register
to to command prompt and type
c:>regsvr32 <complete path of DLL>

open your vb project. go to project-refrences- add the DLL from the list

now create a object
dim obj as new <nameof DLL.ClassName>

now u can use the function

hope this will work

I think thats what i posted in my first post. Please take time to read before posting.

.CPP and .H files can't be directly referenced fronm VB. compile to .DLL file and then instanceate in VB.

I have tried to create a DLL with the C++ & Header file. It is using ATL/COM Model ..So if i tried to create a DLL i am getting Errors. How to create it Properly. PLease can you refer the files Attached COMOutput.h COMOutput.Cpp

This article has been dead for over six months. Start a new discussion instead.