Hi!

I have built an ActiveX DLL using Visual Basic. How can I pass parameters to and from the DLL from C++? Should I use specific Wizards when creating the C++ project in Visual Studio?

Below is explained what works:

This is my simple VB code:
Code:
Public Function OPCconnection_TestFunc()
    MsgBox "You have successfully managed to access VB code from this ActiveX DLL! Congratulations!", vbOKOnly, "Inside the dll"
End Function

To access the VB function in C++, I have this C++ code:
Code:
// dllTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>

#import "OPCclient.dll" no_namespace

void main(void)
{


	CoInitialize(NULL);

	{
	_OPCconnectionPtr pMyInterfaceWrapper(__uuidof(OPCconnection)); 

	printf("Finished Step 1\n");

	result = pMyInterfaceWrapper->OPCconnection_TestFunc();

	printf("Finished Step 2.\n");
	}

	CoUninitialize();	
}
This works fine, but I'm having trouble passing parameters to and from the ActiveX DLL.

There is a .tlh-file generated as well:
Code:
// Created by Microsoft (R) C/C++ Compiler Version 12.00.8447.0 (daaa72a3).
//
// c:\projects\opcclient\dlltest\debug\OPCclient.tlh
//
// C++ source equivalent of Win32 type library OPCclient.dll
// compiler-generated file created 12/09/02 at 14:09:04 - DO NOT EDIT!

#pragma once
#pragma pack(push, 8)

#include <comdef.h>

//
// Forward references and typedefs
//

struct __declspec(uuid("ad76daab-c88c-4d62-b97e-18435d436b74"))
/* dual interface */ _OPCconnection;
struct /* coclass */ OPCconnection;

//
// Smart pointer typedef declarations
//

_COM_SMARTPTR_TYPEDEF(_OPCconnection, __uuidof(_OPCconnection));

//
// Type library items
//

struct __declspec(uuid("ad76daab-c88c-4d62-b97e-18435d436b74"))
_OPCconnection : IDispatch
{
    //
    // Wrapper methods for error-handling
    //

    short OPCconnection_TestFunc ( );

    //
    // Raw methods provided by interface
    //

    virtual HRESULT __stdcall raw_OPCconnection_TestFunc (
        short * _arg1 ) = 0;
};

struct __declspec(uuid("35f913be-9b94-41f3-a676-76292684a385"))
OPCconnection;
    // [ default ] interface _OPCconnection

//
// Wrapper method implementations
//

#include "c:\projects\opcclient\dlltest\debug\OPCclient.tli"

#pragma pack(pop)
I have tried defining the VB function as:
Code:
Public Declare Function OPCconnection_TestFunc Lib "OPCclient" (ByVal A As Integer, ByVal B As Integer) As Integer
    MsgBox "You have successfully managed to access VB code from this ActiveX DLL! Congratulations!", vbOKOnly, "Inside the dll"
    'Print "Inside the dll"

    OPCconnection_TestFunc = A + B
End Function
but then I get compiler error from VB.

I have also tried:
Code:
Public Function OPCconnection_TestFunc(A As Integer, B As Integer) As Integer
    MsgBox "You have successfully managed to access VB code from this ActiveX DLL! Congratulations!", vbOKOnly, "Inside the dll"
    OPCconnection_TestFunc = A + B
End Function
but then in C++, I am told that the function only return a "_variant_t", but takes no parameters in.

What should I do?

Thanks

Torbjørn