|
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>
|
|
|
|
|
The first thing that catches my eye is this line in the .ODL file:
[id(1), helpstring("method GetString")] void GetString(BSTR* str);<br />
This should read:
[id(1), helpstring("method GetString")] void GetString([out, retval]BSTR* str);<br />
Steve
-- modified at 22:00 Sunday 22nd January, 2006
ADDED:
The retval means you should be able to write something like this on the dotNET side:
<br />
s = obj.GetString()<br />
|
|
|
|
|
For dispinterface your note can be more simple:
[id(1), helpstring("method GetString")] BSTR GetString();
With best wishes,
Vita
|
|
|
|
|
hi,
i have developed a small compression C++ COM dll to use in Visual Basic and ASP. i wrote 2 simple functions in COM object
STDMETHODIMP Compress ( BSTR src, VARIANT * target );
STDMETHODIMP Decompress ( VARIANT *src, VARIANT *target );
Compress: receives a string src and compresses it , writes compressed binary byte array to target.
Decompress: receives compressed byte array as src and, writes decompressed string into target string object.
in visual basic all tests go well
Test Visual Basic Function:
Public Sub Test ()
Dim obj = Server.Create("XXX")
Dim str as String, target as Variant , str2 as Variant
str = "testtesttesttesttest" 'any test string
obj.compress( str, target )
obj.decompress( target, str2 )
Msgbox str & vbNewLine & str2
end Sub
My problem is in asp to call decompress() , in asp i get ms vbscript runtime error , err.No = 507
can anyone help for this, google didnot help me much for that
thanx
|
|
|
|
|
My Question is, I have a one dll in that dll contains so many classes, then now I want to export a call and then Import a call.
can you tell me thorugh the example.(How I can export and How I can Import).
Srinu
|
|
|
|
|
It depends on what you want to export and in some cases the the compiler used to do the exporting and the importing. If you just want to export a global function you need to look up extern "C" and __declspec(export) or use a .DEF file. With this technique the compliers used at the exporting and importing ends will not matter. If you want to export a class use __declspec(export) on the class. Using this technique the compilers at each side must use the same name mangling scheme. Or else you can use COM to export a COM object and the importer can be any langauge that supports COM. More information is needed before any more detailed help can be given.
Steve
|
|
|
|
|
|
|
i want to ebook of inside com and if anybody have CHM file then please send or send me a link to download CHM file.
Bankey Khandelwal
Software Engineer
Solversa TechnologiesPvt.Ltd.
15,Yeshwant Nagar
Range Hill Road
Ganeshkhind,Pune-03
bankey.khandelwal@solversa.com
Mobile: +91-9850432990
Office : +91-20-25521888
|
|
|
|
|
I am new to COM and would like to get some information.
I need to create an active document server application.
I have some questions and I would be grateful if you can answer the following
1) Can I create a dll that is an active document server(either mini or full server)? if no, please specify why?
2) What do I need to need to get started with active documents and have complete understanding of what I am doing.
3) Can you point to some online resource which gives indepth implementation details about active documennts. All the links I found in google asked me to create first a skeleton application using wizard which I would to avoid so that I have complete know how of my code.
4) this question might seem stupid but its important for me. Is there any use of active documents other than that your application will not open in a separate window and will be activated inplace.
Thank you
|
|
|
|
|
Hi everyone,
I hope someone has idea on how to do this...
I used this example[^] to create a user control with windows controls with the idea of accessing the client's file system through internet explorer by using this interface as an ActiveX.
The basic idea is that through this control I access some files in a server through FTP that need to be updated, for example in c:\files\ in the client that's looking at this web page.
So, I navigate in IE to this webpage with this user control in the page, and it works ok in my working computer, but when I try to run this update in another computer, I get error messages stating that I don't have the priviledges to access the files in the computer.
Has anyone by any chance tried something like this? accessing the client's file system from IE using a user control?
My studies have brought me to the fact that it's possible to update these files:
- By setting this web site as secure in IE it works ok in other computers.
- By setting security priviledges with the .NET Framework configuration tool the control also works.
Well, what I need is that some how the user doesn't need to do any of these configurations, but somehow the user is asked if it allows the activex component to run and lets it work on his computer.
I've seen that some activex controls prompt if they'll be allowed to run, but for some reason this is not the case with this control.
Thanks for taking the time to read this
daniero
-- modified at 19:32 Wednesday 18th January, 2006
|
|
|
|
|
I am currently following a book on how to sign assemblies with strong names in order to register a serviced component in the into the COM+ catalog and some errors are occuring.
My AssemblyInfo.cs file currently looks like this: (of importance is the AssemblyKeyFile attriubte)
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.EnterpriseServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("StepByStep7_1")]
[assembly: AssemblyDescription("Retrieve and update data from the Northwind database")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StepByStep7_1")]
[assembly: AssemblyCopyright("Copyright © 2006")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ApplicationActivation(ActivationOption.Library)]
[assembly: ApplicationName("NorthwindCS")]
[assembly: AssemblyKeyFile(@"..\..\..\70320.snk")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2d37557e-b619-4092-80e4-4a30e2978021")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
When I build the application I get the following error:
Use command line option '/keyfile' or appropriate project settings instead of 'AssemblyKeyFile'
Can anyone help explain why this error is coming up? The build itself actually does succeed, however it is giving me hassle when I come to register the serviced component in the COM+ catalog. I am presuming that it is because of the error in the build?
I would be very grateful to anyone who can help in order that I may move on in the book as I have just got a second wind to return to my studies and want to make the most of it while it lasts!!!
Thanks
Paul
|
|
|
|
|
I've an ActiveX visible control, written in ATL. Different containers can run it.
Besides, I've a COM (MFC EXE) Server that being informed about any ActiveX properties changes. So I'd like to change the same properties in the other running ActiveX components. In other words all of ActiveX'es could change their properties synchronously.
Thanks.
|
|
|
|
|
Hi,
I have 3 dlls, one is COM DLL and two are c++ dll.
I want to debug the c++ dlls from the com dll through the vb client.
Here the secnario is c++ dll are talking to the mainframe, but when we try to execute the asp client first com dll get activated, from that com dll c++ dlls are gets called.
Pls help me.
Srinu.
-- modified at 9:30 Friday 20th January, 2006
|
|
|
|
|
Now, There is a WebBrowser Control in my application, I hope get the http header by someone Interface.The http header such as
200 ok http/1.1
.
.
type:
set-cookie: !@#$%^&*(
content-length:@#$
..
|
|
|
|
|
The DISPID_BEFORENAVIGATE2 notification has a Headers parameter that looks like it might do what you want.
Steve
|
|
|
|
|
To Stephen Hewitt:
Thanks,but the DISPID_BEFORENAVIGATE2 can only get request http header,not get response http header.
|
|
|
|
|
Hi,
I try to use a Dragonfly ActiveX - XY-Plotter in Matlab SP3.
You will find the Dragonfly ActiveX Library here: http://www.dragonflydas.com/
It's possible to set the properties of the object like colour, grid etc.
I have the problem to plot the data, because I have to call the function PlotXYData of the object with datatype Variant.
I use cell arrays or struct arrays to plot the data, but it didn't work.
I only get the bool value false back.
May you help me, how I should handle functions with datatype Variant in Matlab?
Best Regards
Tolpan
The Matlabcode:
dfpos = get(0,'DefaultFigurePosition');
hfig = figure('Position', dfpos,'Menu', 'none','Name', 'ActX-Test');
hXYChart = actxcontrol('Scope.XYChart.1',[0 0 0 0],hfig);
posfig = get(hfig,'Position'); % Clientfläche des Parent-Windows
sizeactx = [0 0 1 1].*posfig([3 4 3 4]); % Berechnung der ActX-Element-Fläche
move(hXYChart, sizeactx);
hXYChart.invoke('ResetAll'); % Eventuelle Voreinstellungen zurücksetzen
hXYChart.set('bkColor', 140000); % Farbeinstellungen
hXYChart.set('PlotBackgroundColor', 60000);
hXYCurveProp = actxserver('Scope.XYCurveProp.1');
hXYCurveProp.set('Name', 'Curve1');
hXYCurveProp.set('Key', 'Curve1');
hXYCurveProp.set('Unit', 'm');
hXYCurveProp.set('UnitFactor', 1);
hXYCurveProp.set('Max', 100);
hXYCurveProp.set('Min', 0);
hXYCurveProp.set('Color', 0);
hXYCurveProp.set('Width', 1);
hXYCurveProp.set('LineStyle', 0);
hXYCurveProp.set('CurveStyle', 0);
hXYCurveProp.set('PointSize', 6);
hXYCurveProp.set('PointStyle', 2);
% Kurve zum XYChart hinzufügen:
hXYChart.invoke('AddCurve', hXYCurveProp)
% Zeilenvektoren erzeugen:
x = [0 10 20 30 40 50 60 70 80 90 100];
y = [0 10 20 30 40 50 60 70 80 90 100];
xv=num2cell(x);
yv=num2cell(y);
size=length(x);
a=hXYChart.invoke('PlotXYData', 'Curve1', size, xv,yv)
The methods of the object are:
AddCurve = bool AddCurve(handle, handle)
GetCurveProperties = [bool, handle] GetCurveProperties(handle, string)
PlotXYData = bool PlotXYData(handle, string, int32, Variant, Variant)
RemoveCurve = bool RemoveCurve(handle, string)
ResetAll = void ResetAll(handle)
ResetCurve = void ResetCurve(handle, string)
SetAreaCurveTop = void SetAreaCurveTop(handle, string)
SetCurveProp = bool SetCurveProp(handle, string, handle)
hWnd = int32 hWnd(handle)
|
|
|
|
|
I am using the following code to test the speech api,
using SpeechLib;
using System.Security ;
[SuppressUnmanagedCodeSecurityAttribute()]
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
SpVoice voice = new SpVoice();
voice.Speak("Hello",SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
}
catch(Exception ex)
{
Response.Write(ex.ToString()) ;
}
}
I have added a reference to Microsoft Speech API through Add Reference tab-Com Componentes, i have also added the aspcompat=true @Page attribute
But it is giving the error:
System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x8004503A
Please help me to get the code to Speak.
Thanks in advance
This is naresh
|
|
|
|
|
I want to learn COM ,
am a naive to COM .
pls send me some links or simple examples
Vikas Amin
Embin Technology
Bombay
|
|
|
|
|
|
thank you
Vikas Amin
Embin Technology
Bombay
|
|
|
|
|
Hi,
hm... how to start ... I work with MSVS VC++ .NET 2003 (Windows XP SP2)
I created simple MFC DLL with automation (should work in-proccess) and added
a interface to it (based on CCmdTarget class). Everything compilation and
registration succeeds.
In my application which will be using DLL, when I do:
#import "path_to_DLL_file"
use namespace LibTest;
LibTest::ITrackerPtr ptrTrack;
HRESULT hr = CoInitialize( NULL );
hr = ptrTrack.CreateInstance( "LibTest.Tracker" );
CreateInstance returns REGDB_E_CLASSNOTREG error (CoCreateInstance returns
E_OUTOFMEMORY).
When I create similar project in MSVS VC++ 6.0 everything works fine and
problem with initiation DLL doesn't exist.
Anyone knows how to resolve this problem ? Maybe I forgot about something ?
Please help !
Mila
|
|
|
|
|
Hi. I have a problem, which I was trying to solve since a lot of hours and reading docs in the web.
The situation is:
I created an inproc-dll using the ATL-COM Wizard in VC++6. I added an ATL-class using "new atl-object". I added one property for testing purposes. I created the dll and tested it in VB6. It worked. I could create an object in VB6, set the property and read the property.
But:
If I create two objects in VB6 (using SET ... = NEW ...) and set the property in one of them, the property has the same value in the other object. So internally there is only one object with two references.
Or:
If I create an object in VB6 (using SET ... = NEW ... again), set the value and set the object to NOTHING, and then create it by new, the property still has the value.
It seems, that there is only one object in the dll, and it will not be terminated, it lives on and keeps all values ...
(As a workaround I created the same project in the same way, only as an ActiveX-EXE, set the "hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
REGCLS_SINGLEUSE)", and now I can have multiple object with separated properites and lifes and so on. But each object creates a new task in the system, and it is not an inproc-solution.
My Question is:
How can I easily change my inproc-solution, so that I can have multiple instances with separated properties and InitInstance and Terminate and so on?
Or does anyone have any sample for me?
Lots of thanks in advance ...
Heiko from GPSoverIP
|
|
|
|
|
Allowing multiple instances is normal for ATL generated COM objects. Check your source for the following macro:
DECLARE_CLASSFACTORY_SINGLETON
If this is present in an object then the object will behave as you describe.
Steve
|
|
|
|
|