• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

Addtional, more specific, info on VB ActiveX dll called in C++

I have a legacy system written in VS c++ 6.0, from this code I need to call a VB 6.0 ActiveX dll. I have searched and found sveral threads on the subject that have helped but I need a bit more info as my c++ skills are fairly limited.

The issues is the dll has parameters that are strings and passed in by value (byVal) and by reference (ByRef). I can't seem to get it all put togather! There are two public functions within the dll, I am really only interested in calling the CallFunction of the clsTest class; the Workercls was written as public which was an oversight by me.

I have imported the type library through the class wizard, what I need is th actual code to use this dll, passing the the ByVal strings and the ByRef strings so that I can read/manipulate them on the dll's return.

Below is all the code I can think of you Experts might need, if I have missed something please let me know.

Thanks in advance for any and all help!!

VB DLL
Project/dll name is dllTest. 
Class name is clsTest.
VB DLL public function declaration:
Function CallFunction(ByVal sHeaderInformation As String, ByVal sFunctionName As String, ByVal sInputs As String, ByRef sOutputs As String, ByRef sErrors As String) As Integer
 
C++ Header file created by Classview Wizard
// Machine generated IDispatch wrapper class(es) created with ClassWizard
/////////////////////////////////////////////////////////////////////////////
// _clsTest wrapper class
 
class _clsTest : public COleDispatchDriver
{
public:
	_clsTest() {}		// Calls COleDispatchDriver default constructor
	_clsTest(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
	_clsTest(const _clsTest& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}
 
// Attributes
public:
 
// Operations
public:
	short CallFunction(LPCTSTR sHeaderInformation, LPCTSTR sFunctionName, LPCTSTR sInputs, BSTR* sOutputs, BSTR* sErrors);
};
/////////////////////////////////////////////////////////////////////////////
// _Workercls wrapper class
 
class _Workercls : public COleDispatchDriver
{
public:
	_Workercls() {}		// Calls COleDispatchDriver default constructor
	_Workercls(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
	_Workercls(const _Workercls& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}
 
// Attributes
public:
 
// Operations
public:
	// method 'DoScale' not emitted because of invalid return type or parameter type
};
 
CPP file created by Classview Wizard
// Machine generated IDispatch wrapper class(es) created with ClassWizard
 
#include "stdafx.h"
#include "dlltest.h"
 
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
 
 
 
/////////////////////////////////////////////////////////////////////////////
// _clsTest properties
 
/////////////////////////////////////////////////////////////////////////////
// _clsTest operations
 
short _clsTest::CallFunction(LPCTSTR sHeaderInformation, LPCTSTR sFunctionName, LPCTSTR sInputs, BSTR* sOutputs, BSTR* sErrors)
{
	short result;
	static BYTE parms[] =
		VTS_BSTR VTS_BSTR VTS_BSTR VTS_PBSTR VTS_PBSTR;
	InvokeHelper(0x60030000, DISPATCH_METHOD, VT_I2, (void*)&result, parms,
		sHeaderInformation, sFunctionName, sInputs, sOutputs, sErrors);
	return result;
}
 
 
/////////////////////////////////////////////////////////////////////////////
// _Workercls properties
 
/////////////////////////////////////////////////////////////////////////////
// _Workercls operations

Open in new window

0
Jenslove
Asked:
Jenslove
  • 2
  • 2
1 Solution
 
itsmeandnobodyelseCommented:
>>>> LPCTSTR sHeaderInformation

That is a constant pointer to a string which is either an ANSI String (single-byte zero-terminated) or a UNICODE string (double-byte chars and two zero-bytes for termination).

Unfortunately, I don't know whether VB uses UNICODE or ANSI strings. In VC it depends on the project settings. But in any case in VB you need to have a BYREF AS STRING argument cause a pointer in C is an address ('reference') and argument strings in C never were passed 'by value'.
0
 
JensloveAuthor Commented:
Thank you for the help, unfortunately it doesn't help this noob much. :(

My problem is I don't know c++, hardly at all. This is a legacy system I have to 'crack' open so I am looking for code examples on how to call this vb class/function from the c++ app.

And of course this is a 'had to have yesterday' project. *sigh*

Thanks again for you help though. Can you give me an example?
0
 
itsmeandnobodyelseCommented:
>>>> Can you give me an example?
As told I am weak at the VB side. But did you try to replace all these BYVAL arguments with BYREF strings? I am pretty sure that is the only way ...
0
 
ambienceCommented:
Its been a very long time since I worked with MFC/COM but I think it should be something along the lines of

_clsTest clstest;
BOOL res = clstest.CreateDispatch(L"YouApp.ClassProgName", NULL);
if( res == TRUE) 
{
    BSTR outputs, errors;  
    try 
    {
         clstest.CallFunction("
sHeaderInformation
",
 
                         "sFunctionName
",
 "sInputs
",
 
                         &o
utputs
,
 &error
};
         // use output params
         // ...
         // done using stuff


         SysFreeString(outputs);


         SysFreeString(error);
 
    } 
    catch (com_exception& cx) 
    {
    }
}

Hope this helps ...

Open in new window

0
 
ambienceCommented:
Oh and BTW, you need to replace the parameters with actual values. I only used placeholders to show what goes where.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now