Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To: Create a class/dll using another classes TYPE.
Message
General information
Forum:
Visual C++
Category:
Classes
Miscellaneous
Thread ID:
00567225
Message ID:
00568919
Views:
19
This message has been marked as the solution to the initial question of the thread.
First of all, I'd like to recommend an article "Q194873 - HOWTO: Access a Visual Basic ActiveX DLL from Visual C++" in MSKB. IMO it may be very useful.
Below my sample of accessing VB dll with UDT as parameter and return value using #import (method 2 of article):

VC++ code
(Attention: add a "/Zp4" swith to compiler options in order to avoid a problem with incorrectly passed items of structure)
// SFB_test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <stdio.h>
#import "e:\My Projects\vb\sfb\sfb_Types.dll" no_namespace
// atlbase.h required for OLE2A conversion macros
#include <atlbase.h>

int main(int argc, char* argv[])
{
	try
	{
		CoInitialize(NULL);

		Boxes b;
		b.ItemName = SysAllocString(L"This is name of item");
		b.GroupTotal = 156;
		b.x = 3.1415927;

		_SFB_StruPtr ptr;
		ptr.CreateInstance(__uuidof(SFB_Stru));
		ptr->MyFunction(&b);

		USES_CONVERSION;
		Boxes FromVB = ptr->BoxesFunc();
		printf("ItemName: %s\n\r", OLE2A(FromVB.ItemName));
		printf("x: %f y: %f\n\r", FromVB.x, FromVB.y);
	}
	catch(_com_error &e)
	{
		BSTR bstrDesc = e.Description();
	}
	CoUninitialize();

	return 0;
}
VB code
Public Type Boxes
    ItemName As String
    GroupTotal As Integer
    Down As Integer
    Across As Integer
    x As Double
    y As Double
    Arc As String
    Total As Integer
End Type

Public Function MyFunction(b As Boxes)
    Dim msg As String
    msg = "Item: " & b.ItemName & vbCrLf
    msg = msg & " Group total: " & b.GroupTotal & vbCrLf
    msg = msg & " x: " & b.x
    MsgBox msg
End Function

Public Function BoxesFunc() As Boxes
    BoxesFunc.ItemName = "ItemName"
    BoxesFunc.x = 0.123456789
    BoxesFunc.y = 9.87654321
End Function
>Alexander, Thanks for giving me a chance to more clearly explain my adversity.
>I have an established software that allows developer plugins through an existing COM interface. The issue is for the plugin developers. I have provided a sample for VB and VFP developers but I don't know how to do it in VC. I want to provide an example for the VC users to use. The details are:
>
>1) Main 3rd party software: Written primarily in VB
>2) COM DLL containing the object type to be used: Written in VB
>3) The part I need help with: A sample VC project that would incorporate item 2 and provide an interface allowing item one to access various properties
>
>In VB I early bind to the COM dll #2 and create DLL as usual
>In VFP I createobject("SFB_Types.SFB_stru") the COM dll #2 and create DLL as usual
>
>In VC if I use the #imports statement how can I create a dll property that would return the imported struct?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform