Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-04
6
Medium Priority
?
353 Views
Last Modified: 2013-11-25
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
Comment
Question by:Jenslove
  • 2
  • 2
5 Comments
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 22645184
>>>> 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
 

Author Comment

by:Jenslove
ID: 22650354
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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 22654455
>>>> 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
 
LVL 22

Accepted Solution

by:
ambience earned 2000 total points
ID: 22676110
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
 
LVL 22

Expert Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question