Click here to Skip to main content
15,915,752 members
Home / Discussions / COM
   

COM

 
AnswerRe: printer shell extension Pin
eisbaer31122-Feb-06 4:27
eisbaer31122-Feb-06 4:27 
QuestionICopyHook Pin
ragavan23-Jan-06 3:00
ragavan23-Jan-06 3:00 
QuestionCOM client must recompile when server compiled? Pin
WernerP23-Jan-06 1:55
WernerP23-Jan-06 1:55 
Questionwhat is a interface? Pin
vikas amin22-Jan-06 19:28
vikas amin22-Jan-06 19:28 
AnswerRe: what is a interface? Pin
Stephen Hewitt22-Jan-06 22:35
Stephen Hewitt22-Jan-06 22:35 
AnswerRe: what is a interface? Pin
Danish jibbran29-Jan-06 1:37
Danish jibbran29-Jan-06 1:37 
Questionabout IMediaSeeking Pin
abstarsss22-Jan-06 17:57
abstarsss22-Jan-06 17:57 
QuestionAttempting to return a BSTR * from a MFC ActiveX to VB .NET Pin
godspeed12322-Jan-06 7:39
godspeed12322-Jan-06 7:39 
Hi,

I am trying to send a simple string from a ActiveX written in C++ and pop a messageBox out in VB .NET with this string in it. I have tried everything and spoke to many people about this problem.

When I attempt to run the VB Application I get a error telling me

System.Runtime.Services.COMException and with further detail it tells me it is a type Mismatch

I have written a sample program that has a simple function called GetString,

The MessageBox in the function GetString doesnt even pop up

Here is the .IDL File

<code>
#include <idispids.h>

[ uuid(597DC433-D3AC-484E-A91E-3CB9752A7C8A), version(1.0),
helpfile("Test.hlp"),
helpstring("Test ActiveX Control module"),
control ]
library TestLib
{
importlib(STDOLE_TLB);

// Primary dispatch interface for CTestCtrl

[ uuid(444429CA-5912-4EB6-B56F-714EC166420C),
helpstring("Dispatch interface for Test Control")]
dispinterface _DTest
{
properties:
methods:

[id(DISPID_ABOUTBOX)] void AboutBox();
[id(1), helpstring("method GetString")] void GetString(BSTR* str);
};

// Event dispatch interface for CTestCtrl

[ uuid(1EA5A597-A8EE-4A61-A0B5-0CB32CD9ADF2),
helpstring("Event interface for Test Control") ]
dispinterface _DTestEvents
{
properties:
// Event interface has no properties

methods:
};

// Class information for CTestCtrl

[ uuid(2FA19712-DF56-49B0-9DA0-E148FECB25A7),
helpstring("Test Control"), control ]
coclass Test
{
[default] dispinterface _DTest;
[default, source] dispinterface _DTestEvents;
};

};
</code>

Here is the TestCtrl.cpp File

<code>
// TestCtrl.cpp : Implementation of the CTestCtrl ActiveX Control class.

#include "stdafx.h"
#include "Test.h"
#include "TestCtrl.h"
#include "TestPropPage.h"
#include ".\testctrl.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif


IMPLEMENT_DYNCREATE(CTestCtrl, COleControl)



// Message map

BEGIN_MESSAGE_MAP(CTestCtrl, COleControl)
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()



// Dispatch map

BEGIN_DISPATCH_MAP(CTestCtrl, COleControl)
DISP_FUNCTION_ID(CTestCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(CTestCtrl, "GetString", dispidGetString, GetString, VT_EMPTY, VTS_PBSTR)
END_DISPATCH_MAP()



// Event map

BEGIN_EVENT_MAP(CTestCtrl, COleControl)
END_EVENT_MAP()



// Property pages

// TODO: Add more property pages as needed. Remember to increase the count!
BEGIN_PROPPAGEIDS(CTestCtrl, 1)
PROPPAGEID(CTestPropPage::guid)
END_PROPPAGEIDS(CTestCtrl)



// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CTestCtrl, "TEST.TestCtrl.1",
0x2fa19712, 0xdf56, 0x49b0, 0x9d, 0xa0, 0xe1, 0x48, 0xfe, 0xcb, 0x25, 0xa7)



// Type library ID and version

IMPLEMENT_OLETYPELIB(CTestCtrl, _tlid, _wVerMajor, _wVerMinor)



// Interface IDs

const IID BASED_CODE IID_DTest =
{ 0x444429CA, 0x5912, 0x4EB6, { 0xB5, 0x6F, 0x71, 0x4E, 0xC1, 0x66, 0x42, 0xC } };
const IID BASED_CODE IID_DTestEvents =
{ 0x1EA5A597, 0xA8EE, 0x4A61, { 0xA0, 0xB5, 0xC, 0xB3, 0x2C, 0xD9, 0xAD, 0xF2 } };



// Control type information

static const DWORD BASED_CODE _dwTestOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CTestCtrl, IDS_TEST, _dwTestOleMisc)



// CTestCtrl::CTestCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CTestCtrl

BOOL CTestCtrl::CTestCtrlFactory::UpdateRegistry(BOOL bRegister)
{
// TODO: Verify that your control follows apartment-model threading rules.
// Refer to MFC TechNote 64 for more information.
// If your control does not conform to the apartment-model rules, then
// you must modify the code below, changing the 6th parameter from
// afxRegApartmentThreading to 0.

if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_TEST,
IDB_TEST,
afxRegApartmentThreading,
_dwTestOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}



// CTestCtrl::CTestCtrl - Constructor

CTestCtrl::CTestCtrl()
{
InitializeIIDs(&IID_DTest, &IID_DTestEvents);
// TODO: Initialize your control's instance data here.
}



// CTestCtrl::~CTestCtrl - Destructor

CTestCtrl::~CTestCtrl()
{
// TODO: Cleanup your control's instance data here.
}



// CTestCtrl::OnDraw - Drawing function

void CTestCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
if (!pdc)
return;

// TODO: Replace the following code with your own drawing code.
pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
pdc->Ellipse(rcBounds);
}



// CTestCtrl::DoPropExchange - Persistence support

void CTestCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);

// TODO: Call PX_ functions for each persistent custom property.
}



// CTestCtrl::OnResetState - Reset control to default state

void CTestCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange

// TODO: Reset any other control state here.
}



// CTestCtrl::AboutBox - Display an "About" box to the user

void CTestCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_TEST);
dlgAbout.DoModal();
}



// CTestCtrl message handlers

void CTestCtrl::GetString(BSTR* str)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());

// MessageBox( "This is a test" );

// CString tmp = "Hello World";
// *str = tmp.AllocSysString();
}

</code>

And Here is the TestCtrl.h

<code>
#pragma once

// TestCtrl.h : Declaration of the CTestCtrl ActiveX Control class.


// CTestCtrl : See TestCtrl.cpp for implementation.

class CTestCtrl : public COleControl
{
DECLARE_DYNCREATE(CTestCtrl)

// Constructor
public:
CTestCtrl();

// Overrides
public:
virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid);
virtual void DoPropExchange(CPropExchange* pPX);
virtual void OnResetState();

// Implementation
protected:
~CTestCtrl();

DECLARE_OLECREATE_EX(CTestCtrl) // Class factory and guid
DECLARE_OLETYPELIB(CTestCtrl) // GetTypeInfo
DECLARE_PROPPAGEIDS(CTestCtrl) // Property page IDs
DECLARE_OLECTLTYPE(CTestCtrl) // Type name and misc status

// Message maps
DECLARE_MESSAGE_MAP()

// Dispatch maps
DECLARE_DISPATCH_MAP()

afx_msg void AboutBox();

// Event maps
DECLARE_EVENT_MAP()

// Dispatch and event IDs
public:
enum {
dispidGetString = 1L
};
protected:
void GetString(BSTR* str);
};


</code>


The VB Application is as follows:

<code>
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents AxTest1 As AxTestLib.AxTest
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.AxTest1 = New AxTestLib.AxTest
CType(Me.AxTest1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'AxTest1
'
Me.AxTest1.Enabled = True
Me.AxTest1.Location = New System.Drawing.Point(16, 16)
Me.AxTest1.Name = "AxTest1"
Me.AxTest1.OcxState = CType(resources.GetObject("AxTest1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxTest1.Size = New System.Drawing.Size(184, 192)
Me.AxTest1.TabIndex = 0
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.AxTest1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.AxTest1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim test As String

AxTest1.GetString(test) 'ERROR HAPPENS HERE

End Sub
End Class

</code>
AnswerRe: Attempting to return a BSTR * from a MFC ActiveX to VB .NET Pin
Stephen Hewitt22-Jan-06 15:55
Stephen Hewitt22-Jan-06 15:55 
GeneralRe: Attempting to return a BSTR * from a MFC ActiveX to VB .NET Pin
Vi224-Jan-06 4:21
Vi224-Jan-06 4:21 
Questionpass asp byte array to com object? Pin
mack scynox20-Jan-06 23:38
mack scynox20-Jan-06 23:38 
QuestionHow to export a class in c++ dll. Pin
srinu.m20-Jan-06 3:35
srinu.m20-Jan-06 3:35 
AnswerRe: How to export a class in c++ dll. Pin
Stephen Hewitt20-Jan-06 14:53
Stephen Hewitt20-Jan-06 14:53 
AnswerRe: How to export a class in c++ dll. Pin
Stephen Hewitt20-Jan-06 16:33
Stephen Hewitt20-Jan-06 16:33 
GeneralRe: How to export a class in c++ dll. Pin
srinu.m22-Jan-06 15:51
srinu.m22-Jan-06 15:51 
Questionanyboby can give the link for download Ebook of inside com Pin
baldha rakesh19-Jan-06 17:39
baldha rakesh19-Jan-06 17:39 
QuestionI need some info on active documents Pin
UsmanMKhan19-Jan-06 2:30
UsmanMKhan19-Jan-06 2:30 
QuestionAccessing file system in client with .net winform control used as Activex in page Pin
Daniel Santillanes18-Jan-06 13:28
professionalDaniel Santillanes18-Jan-06 13:28 
QuestionSigning Assemblies with strong names Pin
oceanexplorer18-Jan-06 11:46
oceanexplorer18-Jan-06 11:46 
QuestionSet properties in the all ActiveX instances Pin
Andrey200617-Jan-06 23:03
Andrey200617-Jan-06 23:03 
QuestionHow to Debug the dependency dll from the vb Pin
srinu.m17-Jan-06 18:05
srinu.m17-Jan-06 18:05 
QuestionHow to get http response header from IE WebBrowser Control ? Pin
realroot16-Jan-06 18:23
realroot16-Jan-06 18:23 
AnswerRe: How to get http response header from IE WebBrowser Control ? Pin
Stephen Hewitt17-Jan-06 17:46
Stephen Hewitt17-Jan-06 17:46 
GeneralRe: How to get http response header from IE WebBrowser Control ? Pin
realroot17-Jan-06 20:39
realroot17-Jan-06 20:39 
QuestionMatlab ActiveX Variant Datatype Pin
Tolpan16-Jan-06 3:22
Tolpan16-Jan-06 3:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.